AngularJS HTML DOM詳解及示例代碼
以下指令可用于應用程序數(shù)據(jù)綁定到HTML DOM元素的屬性。
| S.No. | 名稱 | 描述 |
|---|---|---|
| 1 | ng-disabled | 禁用一個給定的控制 |
| 2 | ng-show | 顯示一個給定的控制 |
| 3 | ng-hide | 隱藏在給定的控制 |
| 4 | ng-click | 表示AngularJS click事件 |
ng-disabled 指令
添加ng-disabled屬性到一個HTML按鈕,通過它的模型。該模型綁定到復選框,看看以下變化。
<input type="checkbox" ng-model="enableDisableButton">Disable Button <button ng-disabled="enableDisableButton">Click Me!</button>
ng-show 指令
添加ng-show屬性到一個HTML按鈕,并把它傳遞模型。綁定模型到復選框,看看以下變化。
<input type="checkbox" ng-model="showHide1">Show Button <button ng-show="showHide1">Click Me!</button>
ng-hide 指令
添加ng-hide屬性為HTML按鈕,通過它的模型。綁定模型到復選框,看看以下變化。
<input type="checkbox" ng-model="showHide2">Hide Button <button ng-hide="showHide2">Click Me!</button>
ng-click 指令
添加ng-click屬性為HTML按鈕并更新模型。模型綁定HTML看看結(jié)合的變化。
<p>Total click: {{ clickCounter }}</p></td>
<button ng-click="clickCounter = clickCounter + 1">Click Me!</button>
例子
下面的例子將展示上述所有指令。
testAngularJS.html
<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="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</body>
</html>
輸出
在Web瀏覽器打開textAngularJS.html,看到以下結(jié)果:

以上就是對AngularJS HTML DOM資料的整理,后續(xù)繼續(xù)補充相關(guān)資料,謝謝大家對本站的支持!
相關(guān)文章
AngularJS實現(xiàn)動態(tài)編譯添加到dom中的方法
這篇文章主要介紹了AngularJS實現(xiàn)動態(tài)編譯添加到dom中的方法,結(jié)合實例形式分析了AngularJS動態(tài)編輯構(gòu)建模板的相關(guān)操作技巧,需要的朋友可以參考下2016-11-11
Angular.js初始化之ng-app的自動綁定與手動綁定詳解
這篇文章主要給大家介紹了關(guān)于Angular.js初始化之ng-app的自動綁定與手動綁定的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編來一起學習學習吧。2017-07-07
AngularJS使用ng-options指令實現(xiàn)下拉框
這篇文章主要介紹了AngularJS使用ng-options指令實現(xiàn)下拉框效果,ng-option指令使用也很簡單,下文具體給大家說明,對angularjs 下拉框知識感興趣的朋友一起看下吧2016-08-08

