UI-Router的ui-sref创建了错误的href

时间:2016-08-11 02:32:30

标签: angularjs angular-ui-router

我有一个带2个ui-views的SPA:标题和正文。标题由一个控制器运行,处理主体的控制器(取决于状态)调用我创建的服务函数,如下所示:

    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;
    });

标头的控制器用以下方式监听广播:

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

标题的html包含:

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

所以我期望的是:

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

然而,我所呈现的是:

{{1}}

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分: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