0

我有一个单页 web 应用程序,其中任何以请求开头的请求,例如http://localhost/appname/request*,使用 IIS URL 重写模块将主页发送回客户端。

当 Angular 接收到网页时,它会看到路由。我需要确保 Angular 接收到 routeParams。

客户要求:http://localhost/appname/request/param1/param2

$routeProvider.when('/request/:param1/:param2',{
    templateUrl : 'app/views/myView.html',
    controller : 'MyCtrl',
    caseInsensitiveMatch : true
});
$routeProvider.otherwise({ redirectTo: '/' , caseInsensitiveMatch : true });     

$locationProvider.html5Mode(true).hashPrefix('!');

控制器监听$routeChangeSuccess

app.controller('MyCtrl',function($scope){
    $scope.$on('$routeChangeSuccess',function(event,routeData,$timeout,$rootScope){
     //routeData.pathParams are blank    
    });    
});

URL 也更改为主页。即我被重定向到http://localhost/appname.

我做错了什么?

4

1 回答 1

1

如果我理解正确,您想获取路由参数,但正确的方法是将 $routeParams 注入控制器:

app.controller('MyCtrl',function($scope, $routeParams){
    if($routeParams.param1){
        alert('SUPER FLY!');
    }

});

http://docs.angularjs.org/tutorial/step_07

于 2013-10-03T01:11:39.110 回答