Angularjs 角度-当

Angularjs 角度-当,angularjs,Angularjs,在我的Angular应用程序中,如果用户访问的页面id有效,我只希望用户能够访问故事页面 为了实现这一点,我相信(如果有更简单的方法,请纠正我),我需要在路线上工作。但是,如何将:id传递到usefulService中的方法中: .when("/story/:id", { templateUrl: "views/story.html", controller: 'Story' , controllerAs: 'story', resolve

在我的Angular应用程序中,如果用户访问的页面id有效,我只希望用户能够访问故事页面

为了实现这一点,我相信(如果有更简单的方法,请纠正我),我需要在路线上工作。但是,如何将
:id
传递到
usefulService
中的方法中:

.when("/story/:id",
    {
      templateUrl: "views/story.html",
      controller: 'Story' ,
      controllerAs: 'story',
      resolve:{
        "check":function($location, usefulService){
            if(!usefulService.isRealID(id)){ //here is where I want to pass id
                $location.path('/');
            }
        }
      }
    }
)
谢谢你的帮助


谢谢。

您可以使用
$route

.when("/story/:id", {
    templateUrl : "views/story.html",
    controller : 'Story',
    controllerAs : 'story',
    resolve : {
        "check" : function ($location, $route, usefulService) {
            if (!usefulService.isRealID($route.current.pathParams.id)) { //here is where I want to pass id
                $location.path('/');
            }
        }
    }
})

啊!太好了,行得通。显而易见,当你看到!非常感谢。你同意这是最好的方法吗?如果用户访问的页面id是validYep,那么用户就可以访问故事页面,我在自己的应用程序中一直使用这个。