我有 2 个按钮,用于选择我想要解决的 2 种不同情况。当我选择按钮 #2 时,我想禁用输入栏上的自动完成功能(使用 ng-autocomplete 启用),但我无法弄清楚如何轻松地做到这一点(无需完全插入新的 div ,这听起来像是一个坏主意)。
我尝试将值设置为不同的值,但无济于事。有没有办法动态禁用此功能?
有问题的代码:
<input id="businessID" type="text" ng-autocomplete ng-model="autocomplete" placeholder="What business do you want to pay?">
最佳答案
我突然想到一个想法,它认为它可以回答你的问题:
创建 2 个输入:
带有 ng-autocomplete 的一个
<input ng-if="!disabled" id="businessID" type="text" ng-autocomplete ng-model="autocomplete" placeholder="What business do you want to pay?">
第二个没有
<input ng-if="disabled" id="businessID" type="text" ng-model="autocomplete" placeholder="What business do you want to pay?">
然后在输入中,您可以使用范围变量来区分是否禁用。这样,当它被禁用时,您将看到正常的,而何时不是自动完成的。
关于按钮,就这么简单:
<button ng-click="disabled = !disabled">Disable autocomeplete</button>
关于javascript - 禁用 ng-autocomplete (或一般禁用 div 属性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32114529/