Angular如何在解析块中获取路由ID?

时间:2014-07-01 06:04:27

标签: angularjs angularjs-directive angularjs-scope angular-ui angular-ui-bootstrap

我怎样才能得到" pageid"内部解决阻止?

对于每个网址更改,我必须请求服务器以及" pageid"?

我的代码:

app.config(function($routeProvider){
    $routeProvider
      .when('/mainpage/:pageid',
          {
            controller:'ContentController',
                resolve: {
                  data: function ($q, $http) {
                        console.log(window.location.hash)

                    var deferred = $q.defer();
                    $http({method: 'GET', url: mainURL}).then(function(data) {
                      deferred.resolve(data);
                    });
                    return deferred.promise;
                  }
                },                  
                 templateUrl : 'app/partials/masterTemplate.html'
          })
     .otherwise({redirectTo:'/mainpage/home'});
});

1 个答案:

答案 0 :(得分:1)

你可以这样做:

data: function ($http, $routeParams) {
    return $http({
               method: 'GET',
               url: mainURL,
               params: {
                   pageid: $routeParams.pageid
               }
           })
           .then(function(data) {
               return data;
           });
}