AngularJS: ui-router: Do not output link of current state? -
is possible to check state in view , don't output link current (active) state?
currently trying:
<a ng-if="!$state.includes('dashboard.common')" ui-sref="dashboard.common" >dashboard</a> <span ng-if="$state.includes('dashboard.common')">dashboard</span>
of course, decorate ui-sref-active, don't want have link @ all.
any ideas?
the answer provided here
and final version is:
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 can use directive like:
<ui-link sref="dashboard.common"><span translate="my_dashboard">dashboard</span></ui-link>
Comments
Post a Comment