AngularJS HTML DOM



AngularJS provides instructions for binding application data to attributes of HTML DOM elements.


ng-disabled directive

ng-disabled directive binds application data directly to the disabled attribute of HTML.

Instance

<!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>

Run Instance»

Click the "Run Instance" button to view the online instance

Explanation with examples:

ng-disabled The instruction binds the application data "mySwitch" to the disabled attribute of HTML.

ng-model The directive binds "mySwitch" to the content (value) of the HTML input checkbox element.

If mySwitch is true, the button will be disabled:

<p>
<button disabled>Click me! </button>
</p>

If mySwitch is false, the button is available:

<p>
<button>Click me!< /button>
</p>

ng-show directive

ng-show directive hides or shows an HTML element.

Instance

<!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>

Run Instance»

Click the "Run Instance" button to view the online instance

The

ng-show directive shows (hides) HTML elements based on the value of value.

You can use expressions to evaluate Boolean values ​​(true or false):

Example

<!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>

Run Example »

Click the "Run Instance" button to view the online instance


Note#In the next chapter, we will give you more examples of hiding HTML elements by clicking buttons.

ng-hide directive

ng-hide directive is used to hide or show HTML elements.

Instance

<!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>

Run instance»

Click the "Run instance" button to view the online instance