欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

AngularJS HTML DOM详解及示例代码

程序员文章站 2022-06-19 19:24:08
以下指令可用于应用程序数据绑定到html dom元素的属性。 s.no. 名称 描述...

以下指令可用于应用程序数据绑定到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资料的整理,后续继续补充相关资料,谢谢大家对本站的支持!