以下指令可用于应用程序数据绑定到html dom元素的属性。
添加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,看到以下结果:
如对本文有疑问, 点击进行留言回复!!
基于Angular 8和Bootstrap 4实现动态主题切换的示例代码
解决三元运算符 报错“SyntaxError: can''t assign to conditional expression”
解决angular 使用原生拖拽页面卡顿及表单控件输入延迟问题
使用 Angular RouteReuseStrategy 缓存(路由)组件的实例代码
分享Angular http interceptors 拦截器使用(推荐)
网友评论