[英]Disable an ng-click on an ng-repeat
I've read through a bunch of questions on SO and for whatever reason the solutions posted are not working. 我已经阅读了很多有关SO的问题,无论出于何种原因,发布的解决方案均无法正常工作。 I have a list of items that I'm
ng-repeat
ing, and I want to disable two items from being clicked. 我有一个要
ng-repeat
的项目列表,我想禁用两个项目。
<tr ng-repeat="itm in jtc.jobTypes" ng-click="jtc.showAdvanced(itm); setSelected(itm.JobTypeId)" ng-disabled="itm.JobTypeId==-1" ng-class="{selected: itm.JobTypeId === idSelected}">
Only form elements (textbox, button, etc.) can have a disabled
property set on them. 仅表单元素(文本框,按钮等)可以在其上设置
disabled
属性。
To disable a click event on a particular item, check your item ID inside the click handler. 要禁用特定项目的点击事件,请在点击处理程序中检查您的项目ID。
showAdvanced(itm) {
if (itm.JobTypeId != -1) {
// do something
}
}
Further, you shouldn't be calling multiple functions in the ng-click
handler. 此外,您不应该在
ng-click
处理程序中调用多个函数。 Make a separate click handler function and call the other functions from inside it. 制作一个单独的单击处理程序函数,然后从内部调用其他函数。
<tr ng-repeat="itm in jtc.jobTypes" ng-click="onItemClicked(itm)">
And... 和...
onItemClicked(item) {
if (itm.JobTypeId != -1) {
showAdvanced(itm);
setSelected(itm.JobTypeId);
}
}
Try ng-class 尝试ng-class
ng-class="(itm.JobTypeId==-1)?'disableClick':''"
css 的CSS
.disableClick {
pointer-events: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.