2016-08-11 9 views
0

私はui-viewsを2つ持つSPAを持っています:ヘッダとボディ。ヘッダは、一方のコントローラによって実行され、本体をハンドルコントローラは、(状況に応じて)私が作成したサービス機能への呼び出しを行う次のようUI-Routerのui-srefが間違ったhrefを作成しています

/** 
    * Sets the header bar's attributes 
    * 
    * @param inverse bool Whether the color scheme should be inverted 
    * @param button bool Whether the back button should be presented 
    * @param link string The route the back button will take the user to when pressed 
    * @param title string The translation key to use for the title to be shown in the headerbar 
    * @param data string Characters to be inserted in the span next to the title 
    * 
    **/ 
    return { 
     set: function(inverse, button, link, title, data) { 
      // set defaults 
      inverse = typeof inverse !== 'undefined' ? inverse : false; 
      button = typeof button !== 'undefined' ? button : false; 
      link = typeof link !== 'undefined' ? link : $state.current.name; 
      title = typeof title !== 'undefined' ? title : undefined; 
      data = typeof data !== 'undefined' ? data : false; 
      // store for HeaderController to retrieve 
      $localStorage.headerInverse = inverse; 
      $localStorage.headerBackButton = button; 
      $localStorage.headerBackLink = link; 
      $localStorage.headerTitle = title; 
      $localStorage.headerData = data; 

      broadcast.announce('setHeader'); 
     } 
    }; 

ようなので:

header.set(true, true, 'app.search1', 'MY_PROFILE'); 

ヘッダーのコントローラーはで放送に耳を傾け:

broadcast.listenFor('setHeader', function() { 
     vm.headerTitle = $localStorage.headerTitle; // expects the translation key to look up 
     vm.headerData = $localStorage.headerData; 
     vm.headerInverse = $localStorage.headerInverse; 
     vm.headerBackLink = $localStorage.headerBackLink; 
     vm.headerBackButton = $localStorage.headerBackButton; 
     vm.headerMoreIcon = $localStorage.headerMoreIcon; 
    }); 

とヘッダーのHTMLがあります。

<a ui-sref="{{ vm.headerBackLink }}"></a> 

だから私が期待するものです。

<a href="#/search1" ui-sref="app.search1"></a> 

しかし、私は、レンダリングなってることです:

<a href="#/profile" ui-sref="app.search1"></a> 

任意の助けをいただければ幸いです。ありがとう!代わりに、動的状態名を渡すの

+0

可能な重複http://stackoverflow.com/questions/24349731/dynamically- u-sref-angularjsの値を設定してください – MMhunter

答えて

0

、これを試してみてください。

$scope.getLinkUrl = function(){ 
    return $state.href('state-name', {someParam: $scope.someValue}); 
}; 

<a ng-href="{{getLinkUrl()}}">Dynamic Link</a> 

参考:のDynamically set the value of ui-sref Angularjs

+0

ありがとうございました!状態名をui-srefに動的に渡す妥当性をチェックすることは決して考えなかったでしょう。 乾杯! – shiruken

関連する問題