以下指令用于将应用程序数据绑定到HTML DOM元素的属性-
序号 | 名称与说明 |
---|---|
1 |
禁用给定的控件。 |
2 |
显示给定的控件。 |
3 |
隐藏给定的控件。 |
4 |
表示AngularJS click事件。 |
将ng-disabled属性添加到HTML按钮,然后将其传递给模型。将模型绑定到复选框,然后查看变化。
<input type = "checkbox" ng-model = "enableDisableButton">Disable Button<button ng-disabled = "enableDisableButton">Click Me!</button>
将ng-show属性添加到HTML按钮,然后将其传递给模型。将模型绑定到复选框,然后查看变化。
<input type = "checkbox" ng-model = "showHide1">Show Button<button ng-show = "showHide1">Click Me!</button>
将ng-hide属性添加到HTML按钮,然后将其传递给模型。将模型绑定到复选框,然后查看变化。
<input type = "checkbox" ng-model = "showHide2">Hide Button<button ng-hide = "showHide2">Click Me!</button>
将ng-click属性添加到HTML按钮并更新模型。将模型绑定到HTML并查看变化。
<p>Total click: {{ clickCounter }}</p><button ng-click = "clickCounter = clickCounter + 1">Click Me!</button>
以下示例显示了上述所有指令的使用。
<html> <head> <title>AngularJS HTML DOM</title> </head> <body> <h2>AngularJS-HTML DOM示例(cainiaojc.com)</h2> <div ng-app = ""> <table border = "0"> <tr> <td><input type = "checkbox" ng-model = "enableDisableButton">禁用按钮</td> <td><button ng-disabled = "enableDisableButton">Click Me!</button></td> </tr> <tr> <td><input type = "checkbox" ng-model = "showHide1">显示按钮</td> <td><button ng-show = "showHide1">Click Me!</button></td> </tr> <tr> <td><input type = "checkbox" ng-model = "showHide2">隐藏按钮</td> <td><button ng-hide = "showHide2">Click Me!</button></td> </tr> <tr> <td><p>点击总数: {{ clickCounter }}</p></td> <td><button ng-click = "clickCounter = clickCounter + 1">Click Me!</button></td> </tr> </table> </div> <script src = "https://cdn.staticfile.org/angular.js/1.3.14/angular.min.js"> </script> </body> </html>测试看看‹/›
输出结果
在网络浏览器中打开文件testAngularJS.htm并查看结果。