Dynamically set the value of ui-sref Angularjs

前端 未结 12 1799
囚心锁ツ
囚心锁ツ 2020-11-28 04:15

I have searched for a similar question but the ones that came up seem slightly different. I am trying to change the ui-sref=\'\' of a link dynamically (this link points to t

12条回答
  •  一向
    一向 (楼主)
    2020-11-28 04:50

    Looks like this is possible to do after all.

    A breadcrumb on GitHub by one of the ui-router authors led me to try the following:

    Dynamic Link
    

    Then, in your controller:

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

    Turns out, this works like a charm w/ changing scoped values and all. You can even make the 'state-name' string constant reference a scoped value and that will update the href in the view as well :-)

提交回复
热议问题