使用angularjs单击按钮后禁用div
我尝试在使用angularjs单击按钮后禁用一个div。我尝试在我的div中使用ng disabled属性。但我无法做到这一点。有人能帮我解决这个问题吗 我的html代码:使用angularjs单击按钮后禁用div,angularjs,Angularjs,我尝试在使用angularjs单击按钮后禁用一个div。我尝试在我的div中使用ng disabled属性。但我无法做到这一点。有人能帮我解决这个问题吗 我的html代码: <button style="margin-left: 22px; margin-top: 16px; background-color: #73AD21" ng-click="getHome()">Home</button> <div style="margin-top: 15px; di
<button style="margin-left: 22px; margin-top: 16px; background-color: #73AD21" ng-click="getHome()">Home</button>
<div style="margin-top: 15px; display: inline-block"
ng-repeat="imageSource in imageSources">
<img width=40 height=50 style="margin-left: 12px;"
ng-src="{{imageSource}}" /> <br> <span
style="margin-left: 12px;">{{getFilenameFromPath(imageSource)}}</span>
</div>
我添加的html文件
ng class={'disabled':isClicked}
<button style="margin-left: 22px; margin-top: 16px; background-color: #73AD21" ng-click="getHome()" ng-class={'disabled':isClicked}>Home</button>
<div style="margin-top: 15px; display: inline-block"
ng-repeat="imageSource in imageSources">
<img width=40 height=50 style="margin-left: 12px;"
ng-src="{{imageSource}}" /> <br> <span
style="margin-left: 12px;">{{getFilenameFromPath(imageSource)}}</span>
</div>
我还添加了一个css类。已禁用
.disabled{
pointer-events:none;
}
当您单击isClicked Been true并单击button element add.disabled class时为什么不使用ng show/hide或ng if?您真正想要实现的是什么?实际上,我正在为3个不同的页面使用相同的标题。对于某些页面,我想禁用其中一个div,其余的应该保持活动状态。因此,我没有在这里使用显示/隐藏选项。请看类似的问题:您可以使用二进制变量。非常直截了当。我尝试过使用上面建议的代码,但无法禁用div。我没有弄错我正在尝试在单击主页按钮后立即禁用“imageSources”div。您可以在“imageSources”div上添加ng class={'disabled':isclick}此项。不,即使在添加ng类之后,我也无法禁用div={'disabled':在“imageSources”div上单击}
$scope.imageSources = [];
$scope.imageSources.push('images/Open.png');
$scope.imageSources.push('images/New.jpg');
$scope.imageSources.push('images/Save.png');
$scope.getFilenameFromPath = function(filename) {
return filename.split("/")[1].split(".")[0];
}
$scope.isCliked = false;
$scope.getHome = function() {
$scope.isClicked = !$scope.isClicked;
window.location = "./Home.html";
}
.disabled{
pointer-events:none;
}