角度routeParams未定义

伊斯特万

我试图在我的JS中使用routeParams,但是它始终以未定义的形式传入。

app.controller('ShowKey', function($scope, $http, $routeParams, $log) {

  $log.info('SomeCtrl - starting up, yeah!');
  $log.info($routeParams);

  $scope.getKey = function() {
    $log.info($routeParams);
  };
});

除了使用routeParams调用app.controller以外,还有什么需要设置的吗?

米拉德

1-您是否在配置中考虑了任何routeParams?2-如果您想在配置中获取routeParams,那么,您不能,

---您必须使用:

$ route.current.params代替

    app.config(function($routeProvider){
      $routeProvider.when('/path/:yourRouteParam'
       templateUrl:"your template url address",
        controller:'your controller',
        resolve: {
            resolbeObject: function($route){
             //**here you cannot use $routeParam to get "yourRouteParam"** property
            // you must use : $route.current.params
            }
        }
    })
    });

但是在您的控制器中,您可以使用$ route.params获取yourRouteParam,即使您在路由配置中定义了路由参数,如下所示:

       $routeProvider.when('/path/:**yourRouteParam**

注意如果要定义任何路由参数,则必须使用(:),而不是(?)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章