Angularjs 为什么不在Angular JS中使用wotk routeProvider?
我在Angular JS中使用routeProvider:Angularjs 为什么不在Angular JS中使用wotk routeProvider?,angularjs,Angularjs,我在Angular JS中使用routeProvider: .when('/chat/dialog/:id', { controller: 'ChatController' }); 在控制器中,我有: if($routeParams.id) { alert('ok'); } 我的URL如下所示: http://site-dev.com/chat/dialog/1 链接是: 为什么在Angular JS中不工作 控制器: .controller('ChatController
.when('/chat/dialog/:id', {
controller: 'ChatController'
});
在控制器中,我有:
if($routeParams.id) {
alert('ok');
}
我的URL如下所示:
http://site-dev.com/chat/dialog/1
链接是:
为什么在Angular JS中不工作
控制器:
.controller('ChatController', ['$scope', '$sce', '$http', '$location', '$anchorScroll', '$timeout', '$routeParams', function ($scope, $sce, $http, $location, $anchorScroll, $timeout, $routeParams, ) {
if($routeParams.id) {
alert('ok');
}
}])
.config(function ($locationProvider, $routeProvider) {
$routeProvider
.when('/profile/personal/:type', {
templateUrl: '/public/html/personal.html',
controller: 'EditProfileController'
})
/* Chat */
.when('/chat/dialog/:id', {
controller: 'ChatController'
});
})
路由:
.controller('ChatController', ['$scope', '$sce', '$http', '$location', '$anchorScroll', '$timeout', '$routeParams', function ($scope, $sce, $http, $location, $anchorScroll, $timeout, $routeParams, ) {
if($routeParams.id) {
alert('ok');
}
}])
.config(function ($locationProvider, $routeProvider) {
$routeProvider
.when('/profile/personal/:type', {
templateUrl: '/public/html/personal.html',
controller: 'EditProfileController'
})
/* Chat */
.when('/chat/dialog/:id', {
controller: 'ChatController'
});
})
尝试添加到
头标签
,如下所示:
<head>
<base href="/">
</head>
您能提供更详细的代码吗?您的完整路由配置、控制器代码。还有,什么不起作用?路线?还是警报?还是别的什么?如果是条件中的警报,一个猜测是您没有将$routeParams注入控制器Does not workalert()
,我更新了问题,添加了更多细节,比如在函数定义中有一个额外的逗号-函数($scope,$sce,$http,$location,$anchorScroll,$timeout,$routeParams,)不,抱歉,在代码中没有commaDid,您将ngRoute注入了您的应用程序?首先尝试检查您是否可以访问url中的id,级别为:“/chat/:id”请解释更多信息