【问题标题】:Getting state.params in ui-router alpha for component在组件的 ui-router alpha 中获取 state.params
【发布时间】:2016-11-20 22:01:17
【问题描述】:

我正在使用 angular-ui-router 1.0 。我正在尝试在使用组件时检索参数,我尝试过旧的 $state.params$stateparams 但这不起作用。我不能使用解析,因为我们正在使用一些带有“ocLazyLoad”的动态路由。有什么建议吗?

类似:

$stateProvider
  .state('test', {
    url: "/test/:id",
    component: "myComponent"
});

【问题讨论】:

    标签: angularjs angular-ui-router


    【解决方案1】:

    有错别字。像 :id 一样不能被识别为参数。 (/ 不见了)

    url: "/test/:id",
    

    【讨论】:

    • 嗨,Ferox,错字只是我在这里发布的代码的一部分,在代码中没有问题。不过我在帖子里更正了。谢谢
    【解决方案2】:

    我不确定你是否在问这个问题,但可以像下面这样访问状态参数

    .state('question',{
       url : '/question/:id' // or url : '/question/{id}'
       controller : 'SomeController',
       component : 'someComponent'
    });
    

    并以

    的身份访问参数
     .controller('SomeController',function($state,$stateParams){
        $scope.id = $stateParams.id;
    
      });
    

    【讨论】:

      猜你喜欢
      • 2014-05-29
      • 2016-05-13
      • 2016-09-27
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      • 2017-08-05
      • 1970-01-01
      • 2017-05-21
      相关资源
      最近更新 更多