目录

AngularJS - HTML DOM( HTML DOM)

以下指令用于将应用程序数据绑定到HTML DOM元素的属性 -

Sr.No. 名称和描述
1

ng-disabled

禁用给定的控件。

2

ng-show

显示给定的控件。

3

ng-hide

隐藏一个给定的控件。

4

ng-click

表示AngularJS单击事件。

ng-disabled Directive

将ng-disabled属性添加到HTML按钮并将其传递给模型。 将模型绑定到复选框并查看变体。

<input type = "checkbox" ng-model = "enableDisableButton">Disable Button
<button ng-disabled = "enableDisableButton">Click Me!</button>

ng-show Directive

将ng-show属性添加到HTML按钮并将其传递给模型。 将模型绑定到复选框并查看变体。

<input type = "checkbox" ng-model = "showHide1">Show Button
<button ng-show = "showHide1">Click Me!</button>

ng-hide Directive

将ng-hide属性添加到HTML按钮并将其传递给模型。 将模型绑定到复选框并查看变体。

<input type = "checkbox" ng-model = "showHide2">Hide Button
<button ng-hide = "showHide2">Click Me!</button>

ng-click Directive

将ng-click属性添加到HTML按钮并更新模型。 将模型绑定到HTML并查看变体。

<p>Total click: {{ clickCounter }}</p>
<button ng-click = "clickCounter = clickCounter + 1">Click Me!</button>

例子 (Example)

以下示例显示了上述所有指令的使用。

testAngularJS.htm

<html>
   <head>
      <title>AngularJS HTML DOM</title>
   </head>
   <body>
      <h2>AngularJS Sample Application</h2>
      <div ng-app = "">
         <table border = "0">
            <tr>
               <td><input type = "checkbox" ng-model = "enableDisableButton">Disable Button</td>
               <td><button ng-disabled = "enableDisableButton">Click Me!</button></td>
            </tr>
            <tr>
               <td><input type = "checkbox" ng-model = "showHide1">Show Button</td>
               <td><button ng-show = "showHide1">Click Me!</button></td>
            </tr>
            <tr>
               <td><input type = "checkbox" ng-model = "showHide2">Hide Button</td>
               <td><button ng-hide = "showHide2">Click Me!</button></td>
            </tr>
            <tr>
               <td><p>Total click: {{ clickCounter }}</p></td>
               <td><button ng-click = "clickCounter = clickCounter + 1">Click Me!</button></td>
            </tr>
         </table>
      </div>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
      </script>
   </body>
</html>

输出 (Output)

在Web浏览器中打开文件testAngularJS.htm并查看结果。

新页面打开
↑回到顶部↑
WIKI教程 @2018