当前位置: 移动技术网 > IT编程>脚本编程>AngularJs > 简介AngularJS的HTML DOM支持情况

简介AngularJS的HTML DOM支持情况

2019年05月29日  | 移动技术网IT编程  | 我要评论

以下指令可用于应用程序数据绑定到html dom元素的属性。

201561794017811.jpg (742×213)

 添加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,看到以下结果:

201561794134891.png (694×337)

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网