AngularJS HTML DOM详解及示例代码
2019/6/27 22:12:14
本文主要是介绍AngularJS HTML DOM详解及示例代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
以下指令可用于应用程序数据绑定到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看看结合的变化。
<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,看到以下结果:
以上就是对AngularJS HTML DOM资料的整理,后续继续补充相关资料,谢谢大家对本站的支持!
这篇关于AngularJS HTML DOM详解及示例代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist
- 2024-03-11icons for vue
- 2024-03-07breadcrumbs react js
- 2024-03-06react login page example
- 2024-03-06react router uselocation
- 2024-03-04postgres jsonb_set