我有一个有两个状态的应用程序:
profile
settings
我在我的整个应用程序中有一个重复的链接:
<a ui-sref="profile({id:profile.id})" ui-sref-active="active">Current state + ID</a>
如何将ui-sref
更改为动态的?-表示当前状态以及所需的当前stateParam (即id
)。
在找到解决方案时,请记住,我希望避免使用ui-sref-active
,因此我宁愿避免使用这样的东西。
发布于 2016-06-30 03:38:57
我认为ui-sref
会将(和)中的内容解析为表达式。
所以你要做的就是这个。
<a ng-repeat="step in steps" ui-sref="{{step.state}}(step.param)"></a>
发布于 2016-06-30 03:42:58
我想最安全和最容易理解的方法是使用简单的if else
<div ng-if="checkState == 'profile'">
<a ui-sref="profile({id:profile.id})" ui-sref-active="active">Current state + ID</a>
</div>
<div ng-if="checkState == 'settings'">
<a ui-sref="settings({id:profile.id})" ui-sref-active="active">Current state + ID</a>
</div>
肯定会成功的..。
发布于 2016-06-30 03:47:27
$scope.routers = [
{
state: 'profile',
params: {id: 1}
},
{
state: 'settings',
params: {id: 1}
}
];
查看:
<a ng-repeat="router in routers" ui-sref="{{router.state}}(router.params)"></a>
https://stackoverflow.com/questions/38113541
复制相似问题