2017-01-06 159 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」是我們傳遞的對象。 –