是否可以检查视图中的状态并且不输出当前(活动)状态的链接?
目前正在尝试:
<a ng-if="!$state.includes('dashboard.common')" ui-sref="dashboard.common" >Dashboard</a>
<span ng-if="$state.includes('dashboard.common')">Dashboard</span>
当然,我可以用ui-sref-active来装饰它,但我根本不想要链接。
有什么想法吗?
答案 0 :(得分:0)
答案是here
我的最终版本是:
angular.module('ui')
.directive('uiLink', function($state) {
'use strict';
return {
restrict: 'E',
transclude: true,
template: [
'<a ui-sref="{{uiSref}}" ng-if="!isCurrent()" ng-transclude></a>',
'<span ng-if="isCurrent()" ng-transclude></span>'
].join(''),
link: function(scope, element, attrs) {
scope.uiSref = attrs.sref;
scope.isCurrent = function() {
return $state.includes(attrs.sref);
};
}
};
});
现在您可以使用此指令,如:
<ui-link sref="dashboard.common"><span translate="MY_DASHBOARD">Dashboard</span></ui-link>