Html DOM
In AngularJS, some directives can be used to bind application data to attributes of HTML DOM elements.
These directives are:
Directive |
Description |
ng-disabled |
It disables a given control. |
ng-show |
It shows a given control. |
ng-hide |
It hides a given control. |
ng-click |
It represents an AangularJS click event. |
ng-disabled directive:The ng-disabled directive binds AngularJS application data to the disabled attribute of HTML elements. In the below code, it binds a model to a checkbox.
Syntax:
<input type = "checkbox" ng-model = "enableDisableButton">Disable Button
<button ng-disabled = "enableDisableButton">Click Me!</button>
ng-show directive: The ng-show directive shows or hides an HTML element. In the below code, it binds a model to a checkbox.
Syntax:
<input type = "checkbox" ng-model = "showHide1">Show Button
<button ng-show = "showHide1">Click Me!</button>
ng-hide directive: The ng-hide directive hides or shows an HTML element. In the below code, it binds a model to a checkbox.
<input type = "checkbox" ng-model = "showHide2">Hide Button
<button ng-hide = "showHide2">Click Me!</button>
ng-click directive: The ng-click directive counts the total clicks an HTML element. In the below code, it binds a model to a checkbox.
<p>Total click: {{ clickCounter }}</p>
<button ng-click = "clickCounter = clickCounter + 1">Click Me!</button>
- ng-if,ng-disable,ng-readonly,click me buttons.
<html>
<head>
<script src="angular.min.js"></script>
<style>
div {
width: 100%;
height: 50px;
display: block;
margin: 15px 0 0 10px;
}
</style>
</head>
<body ng-app ng-init="checked=true" >
<h2> In this Directives are HTML DOM</h2>
Click Me: <input type="checkbox" ng-model="checked" /> <br />
<div>
New: <input ng-if="checked" type="text" />
</div>
<div>
Read-only: <input ng-readonly="checked" type="text" value="This is read-only." />
</div>
<div>
Disabled: <input ng-disabled="checked" type="text" value="This is disabled." />
</div>
</body>
</html>
- ng-show and disable
<html>
<head>
<script src="angular.min.js"></script>
<style>
div {
width: 100%;
height: 50px;
display: block;
margin: 15px 0 0 10px;
}
</style>
</head>
<body ng-app ng-init="checked=true" >
<h2>Disable And Show Buttons</h2>
<input type = "checkbox" ng-model = "showHide1">Show Button
<button ng-show = "showHide1">Click Me!</button> <br>
<input type = "checkbox" ng-model = "enableDisableButton">Disable Button
<button ng-disabled = "enableDisableButton">Click Me!</button>
</body>
</html>
ng-show directive: The ng-show directive shows or hides an HTML element. In the below code, it binds a model to a checkbox.
3)Check the box and after show the div with message:
<html>
<script src="angular.min.js"></script>
<style>
.effect
{
background-color:#0099FF;
font:Arial, Helvetica, sans-serif;
}
</style>
<body>
<div ng-app="">
<form>
Check to show this:
<input type="checkbox" ng-model="myVar">
</form>
<div class=effect>
<h2 ng-show="myVar">Hello! About Vision Computers </h2>
<p ng-show="myVar">
Vision Computers established in the year 1992 by D.G.Prasad.<br>
vision computers is so experiance institute in vuyyuru ...
</p>
</div>
</div>
<p>The ng-show attribute is set to true when the checkbox is checked.</p>
</body>
</html>
Let's take an example to deploy the all above directives and test the variations:
- ng-show,ng-disable,ng-hide
<html>
<head>
<title>AngularJS HTML DOM</title>
</head>
<body>
<h3>AngularJS Ng-options</h3>
<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 ="angular.min.js"></script>
</body>
</html>
For
More Explanation
&
Online Classes
More Explanation
&
Online Classes
Contact Us:
+919885348743
+919885348743