我的代码看起来像这样:
<a ng-disabled="!access.authenticated"
data-ng-class="{ 'current': $state.includes('home'), 'disabled': !access.authenticated } "
href="/home/overview"
title="Home">
<i class="fa fa-home fa-fw"></i>
</a>
Run Code Online (Sandbox Code Playgroud)
我想这样做,以便当access.authenticated为false时,无法单击该链接.我想到的是将链接更改为按钮,然后将其设置为链接样式.但是这不起作用,因为按钮不会导致页面URL更改.
<button ng-disabled="!access.authenticated"
data-ng-class="{ 'current': $state.includes('home'), 'disabled': !access.authenticated } "
href="/home/overview"
title="Home">
<i class="fa fa-home fa-fw"></i>
</button>
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何做我需要的东西吗?
这是一个简单的指令,它拦截click事件并阻止基于范围变量的页面转换:
module.directive('myLink', function() {
return {
restrict: 'A',
scope: {
enabled: '=myLink'
},
link: function(scope, element, attrs) {
element.bind('click', function(event) {
if(!scope.enabled) {
event.preventDefault();
}
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
你可以像这样使用它:
<a my-link="linkEnabled" data-ng-class="{'disabled': !linkEnabled}" href="/home/overview">
<i class="fa fa-home fa-fw">Link</i>
</a>
Run Code Online (Sandbox Code Playgroud)
CSS:
.inactive {
color: #ccc;
pointer-events: none;
cursor: default;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<a href="some.html" ng-class="access.authenticated ? '' : 'inactive'">some link</a>
Run Code Online (Sandbox Code Playgroud)
看看这个小提琴.
| 归档时间: |
|
| 查看次数: |
23718 次 |
| 最近记录: |