Home > Web Front-end > JS Tutorial > Introduction to AngularJS's HTML DOM support_AngularJS

Introduction to AngularJS's HTML DOM support_AngularJS

WBOY
Release: 2016-05-16 15:54:42
Original
1154 people have browsed it

The following directives can be used to apply data binding to attributes of HTML DOM elements.

201561794017811.jpg (742×213)

Add the ng-show attribute to an HTML button and pass it to the model. Bind the model to the checkbox and see the following changes.

<input type="checkbox" ng-model="showHide1">Show Button
<button ng-show="showHide1">Click Me!</button>

Copy after login

ng-hide command

Add ng-hide attribute to HTML button, via its model. Bind the model to the checkbox and see the following changes.

<input type="checkbox" ng-model="showHide2">Hide Button
<button ng-hide="showHide2">Click Me!</button>

Copy after login

ng-click command

Add ng-click attribute to HTML button and update model. Model binding HTML to see the binding changes.

<p>Total click: {{ clickCounter }}</p></td>
<button ng-click="clickCounter = clickCounter + 1">Click Me!</button>

Copy after login

Example

The following example will demonstrate all the above commands.
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>

Copy after login

Output

Open textAngularJS.html in a web browser and see the following results:

201561794134891.png (694×337)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template