Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 为什么不在Angular JS中使用wotk routeProvider?_Angularjs - Fatal编程技术网

Angularjs 为什么不在Angular JS中使用wotk 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

我在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', ['$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 work
alert()
,我更新了问题,添加了更多细节,比如在函数定义中有一个额外的逗号-函数($scope,$sce,$http,$location,$anchorScroll,$timeout,$routeParams,)不,抱歉,在代码中没有commaDid,您将ngRoute注入了您的应用程序?首先尝试检查您是否可以访问url中的id,级别为:“/chat/:id”请解释更多信息