由网友(三千浮华一回瞬)分享简介:有可能的视图以检查状态,不输出链接当前(活动)的状态?Is it possible to check state in the view and don't output the link for current (active) state?目前尝试:有可能的视图以检查状态,不输出链接当前(活动)的状态?
Is it possible to check state in the view and don't output the link for current (active) state?
目前尝试:
<a ng-if="!$state.includes('dashboard.common')" ui-sref="dashboard.common" >Dashboard</a>
<span ng-if="$state.includes('dashboard.common')">Dashboard</span>
当然,我可以装饰它UI的SREF主动的,但我不希望有联系的。
Of course, I could decorate it with ui-sref-active, but I don't want to have link at all.
任何想法?
推荐答案
提供了答案这里
和我最后的版本是:
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);
};
}
};
});
所以现在你可以使用这个指令,如:
so now you can use this directive like:
<ui-link sref="dashboard.common"><span translate="MY_DASHBOARD">Dashboard</span></ui-link>
相关推荐
最新文章