Javascript 使用$routeParams,CSS不会';t载荷
当在ngRoute中使用参数并直接访问URL(而不是通过站点内部的链接)时,CSS不会加载。除了Javascript 使用$routeParams,CSS不会';t载荷,javascript,css,angularjs,angularjs-ng-route,Javascript,Css,Angularjs,Angularjs Ng Route,当在ngRoute中使用参数并直接访问URL(而不是通过站点内部的链接)时,CSS不会加载。除了/chef/:id之外,我的所有路线都运行良好。我用的是约曼的,我用的是grunt-service 这是我的路线代码: angular .module('agFrontApp', [ 'configuration', 'LocalStorageModule', 'ngCookies', 'ngRoute',
/chef/:id
之外,我的所有路线都运行良好。我用的是约曼的,我用的是grunt-service
这是我的路线代码:
angular
.module('agFrontApp', [
'configuration',
'LocalStorageModule',
'ngCookies',
'ngRoute',
'ngSanitize',
'ngTouch'
])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: '../views/main_view.html',
controller: 'MainCtrl',
controllerAs: 'MainCtrl',
})
.when('/login', {
templateUrl: '../views/login_view.html',
controller: 'LoginCtrl',
controllerAs: 'login',
})
.when('/chefs', {
templateUrl: '../views/chef_list_view.html',
controller: 'ChefListController',
controllerAs: 'chefs',
})
.when('/chef/:id', {
templateUrl: '../views/chef_detail_view.html',
controller: 'ChefDetailController',
controllerAs: 'chef'
})
.when('/receitas', {
templateUrl: '../views/recipe_list_view.html',
controller: 'RecipeListController',
controllerAs: 'recipe'
})
.when('/perfil', {
templateUrl: '../views/perfil_view.html',
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
});
这是/chef/:id
的控制器:
'use strict';
(function() {
function ChefDetailController($routeParams, $scope, $log, Chefs) {
var vm = this;
Chefs.getChef($routeParams.id)
.then(function(data) {
$log.log('success');
})
.fail(function(data) {
$log.log('something went wrong');
});
}
angular.module('agFrontApp')
.controller('ChefDetailController',
[ '$routeParams', '$scope', '$log', 'Chefs', ChefDetailController]);
})();
我做错了什么
编辑:
下面是chef_detail_view.html:您很可能使用类似这样的相对url加载CSS
<link rel="stylesheet" href="styles/style.css" />
问题是在HTML5模式下,您的厨师url是/chef/123
,因此浏览器试图从中加载您的CSS
/chef/styles/style.css
您需要关闭HTML5模式或将样式表href更改为根相关(例如/styles/style.css
)我们可以看到用于该路线的模板代码吗,这里是chef\u detail\u view.html:这里是index.html,模板加载到: