2017-01-06 112 views
0

发送PARAMS我在config.js的状态看起来像这样:角JS UI路由器在URL

  state("link_redirect", { 
       url: "/link-redirect/", 
       controller: "LinkRedirectCtrl", 
       title: "Redirect Link", 
       params: {endpoint: null} 
      }); 

我不想改变状态定义如上图所示,还是我怎么能发送endpoint params在URL中,以便我可以使用$ stateParams服务在我的控制器中获取它?

+0

如果你希望''stateParams'可以访问某些东西,你需要将它添加到你的url中,如下所示:'url:“/ link-redirect /:endpoint”' – Yaser

回答

1

有两种方法可以访问状态参数。发送你的状态定义

state("link_redirect", { 
      url: "/link-redirect", 
      controller: "LinkRedirectCtrl", 
      title: "Redirect Link", 
      params: {endpoint: null} 
     }); 

访问他们喜欢,$stateParams.params.endpoint

但是,如果你希望你的endpoint可见的网址,你必须把像

url: "/link-redirect/:endpoint" 

删除params: {endpoint: null}

和访问它是这样的$stateParams.endpoint

+0

你确定何时有参数:{endpoint: null},我们需要访问像$ stateParams.params.endpoint而不是像$ stateParams.endpoint –

+0

是的,我相信。你可以试试看。 “params”是我们传递的对象。 –