Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 DOM 元素(我分配给我的控制器的元素的子元素),我希望在添加类“ianctive”(这使元素看起来不活动 - 通过将其变灰)后禁用所有 AngularJS 交互该元素(在本例中为 ng-click 和所有输入)。
定义一个模型属性来跟踪启用/禁用状态,然后将 ng-disable 指令添加到所有表单元素。对于 ng-click,修改表达式以同时查看这个新模型属性以确定它们是否应该执行任何操作。
例如,如果您的新模型属性是 $scope.inactive:
<input type="text" ng-disabled="inactive" ng-model="..."> <a ng-click="inactive || (prop1=prop1 + 1)">click to increase</a> {{prop1}}
小提琴