问题是,如果cancelTicket === false,那么ng-click会对这样的事件起作用.我该如何阻止呢?
<div class="btn-block save-changes padding-10" ng-class="{'gray':cancelTicket===false,'secondary-button':cancelTicket===true}" ng-click="CancelTicket(ticketPin)" ng-disabled="cancelTicket===false" style="display: table;"> <div class="button-container padding3" ng-class="{'pointer':cancelTicket===true}"> <button-spinner promise="cancelPromise"></button-spinner> <div style="display: inline-block !important;"> @Translator.Translate("CANCEL") </div> </div> </div>
解决方法
即使div被禁用也会触发事件.
您可以通过对isDisabled ||等表达式的惰性评估来避免这种情况action()如果isDisabled为true,则不会调用动作.
在你的情况下,它将是:
ng-click="cancelTicket === false || CancelTicket(ticketPin)"