当前位置: 移动技术网 > IT编程>脚本编程>AngularJs > AngularJS 入门教程之HTML DOM实例详解

AngularJS 入门教程之HTML DOM实例详解

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

angularjs html dom

angularjs 为 html dom 元素的属性提供了绑定应用数据的指令。

ng-disabled 指令

ng-disabled 指令直接绑定应用程序数据到 html 的 disabled 属性。

angularjs 实例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="" ng-init="myswitch=true">
<p>
<button ng-disabled="myswitch">点我!</button>
</p>
<p>
<input type="checkbox" ng-model="myswitch"/>按钮
</p>
<p>
{{ myswitch }}
</p>
</div> 

</body>
</html>

运行效果:

按钮

true

实例讲解:

ng-disabled 指令绑定应用程序数据 "myswitch" 到 html 的 disabled 属性。

ng-model 指令绑定 "myswitch" 到 html input checkbox 元素的内容(value)。

如果 myswitch 为true, 按钮将不可用:

<p>
<button disabled>点我!</button>
</p>

如果 myswitch 为false, 按钮则可用:

<p>
<button>点我!</button>
</p>

ng-show 指令

ng-show 指令隐藏或显示一个 html 元素。

angularjs 实例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="">

<p ng-show="true">我是可见的。</p>

<p ng-show="false">我是不可见的。</p>

</div> 

</body>
</html>

运行效果:

我是可见的。

ng-show 指令根据 value 的值来显示(隐藏)html 元素。

你可以使用表达式来计算布尔值( true 或 false):

angularjs 实例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="" ng-init="hour=13">

<p ng-show="hour > 12">我是可见的。</p>

</div>

</body>
</html>

运行结果:

我是可见的。

note 在下一个章节中,我们将为大家更多通过点击按钮来隐藏 html 元素的实例。

ng-hide 指令

ng-hide 指令用于隐藏或显示 html 元素。

angularjs 实例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="">

<p ng-hide="true">我是不可见的。</p>

<p ng-hide="false">我是可见的。</p>

</div> 

</body>
</html>

运行结果:

我是可见的。

以上就是对angularjs html dom 资料的整理,后续继续补充,希望能帮助编程angularjs的朋友。

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

相关文章:

验证码:
移动技术网