Introduction to AngularJS HTML DOM

AngularJS has directives for binding application data to the attributes of HTML DOM elements. The logical structure of documents and documents are accessed and manipulated are defined using DOM elements. It defines events, methods, properties for all HTML elements as objects. DOM in AngularJS acts as an API (programming interface) for javascript.

These directives are:

ng-disabledIt disables a given control.
ng-showIt shows a given control.
ng-hideIt hides a given control.
ng-clickIt represents an AangularJS click event.

 Why DOM is used?

A programmer can use DOM in AngularJS for the following purposes:

  • Documents are built using DOM elements.
  • A Programmer can navigate documents structure with DOM elements.
  • A programmer can add elements and content with DOM elements.
  • Programmer can modify elements and content with DOM elements.

The ng-disabled Directive

The ng-disabled directive binds AngularJS application data to the disabled attribute of HTML elements.

The Syntax

<strong> od ng-disabled-</strong>&lt;input type = "checkbox" ng-model = "enableDisableButton">To disable a button&lt;button ng-disabled = "enableDisableButton">Click&lt;/button>

AngularJS Example

<div ng-app="" ng-init="mySwitch=true">

<button ng-disabled="mySwitch">Click Me!</button>

<input type="checkbox" ng-model="mySwitch">Button

{{ mySwitch }}


Application explained:

The ng-disabled directive binds the application data mySwitch to the HTML button’s disabled attribute. The ng-model directive binds the value of the HTML checkbox element to the value of mySwitch. If the value of mySwitch evaluates to true, the button will be disabled: 

<button disabled>Click Me!</button>

If the value of mySwitch evaluates to false, the button will not be disabled:

<button>Click Me!</button>

The ng-show Directive

The ng-show directive shows or hides an HTML element.

The syntax of ng-show-

&lt;input type = "checkbox" ng-model = "showHide1">To show a Button&lt;button ng-show = "showHide1">Click &lt;/button>

AngularJS Example

<div ng-app="">

<p ng-show="true">I am visible.</p>

<p ng-show="false">I am not visible.</p>


The ng-show directive shows (or hides) an HTML element based on the value of ng-show. You can use any expression that evaluates to true or false:

AngularJS Example

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

<p ng-show="hour > 12">I am visible.</p>


The ng-hide Directive

The ng-hide directive hides or shows an HTML element.

The syntax of ng-hide-

&lt;input type = "checkbox" ng-model = "showHide2">To hide a Button&lt;
button ng-hide = "showHide2">Click&lt;/button>

AngularJS Example

<div ng-app="">

<p ng-hide="true">I am not visible.</p>

<p ng-hide="false">I am visible.</p>



The following example shows use of all the above mentioned directives.

iv. ng-click

We can use ng-click for representing an angularjs click event. We can use it by adding it to an HTML button and pass it to model

The syntax of ng-click-

&lt;p>Number <strong>of</strong> click: {{ clickCounter }}&lt;/p>&lt;button ng-click = "clickCounter = clickCounter + 1">Click &lt;/button>

Example of ng-click-

DOCTYPE html> ; html>;script src="
min.js">&lt;/script>&lt;div ng-app="">&lt;p>Total number <strong>of</strong> Clicks: {{ Counts }}&lt;/p>&lt;button ng-click = "Counts = Counts+ 1">Click Here!&lt;/button>&lt;/div>&lt;/body>&lt;/html>


Total number of Clicks: 4


      <title>AngularJS HTML DOM</title>
      <h2>AngularJS Sample Application</h2>
      <div ng-app = "">
         <table border = "0">
               <td><input type = "checkbox" ng-model = "enableDisableButton">Disable Button</td>
               <td><button ng-disabled = "enableDisableButton">Click Me!</button></td>
               <td><input type = "checkbox" ng-model = "showHide1">Show Button</td>
               <td><button ng-show = "showHide1">Click Me!</button></td>
               <td><input type = "checkbox" ng-model = "showHide2">Hide Button</td>
               <td><button ng-hide = "showHide2">Click Me!</button></td>
               <td><p>Total click: {{ clickCounter }}</p></td>
               <td><button ng-click = "clickCounter = clickCounter + 1">Click Me!</button></td>
      <script src = "">


Open the file testAngularJS.htm in a web browser and see the result.

AngularJS Sample Application

Disable ButtonClick Me!
Show Button
Hide ButtonClick Me!
Total click:Click Me!


A document object model is used for manipulating and accessing the contents in documents created using HTML or XML. In the above article, we have discussed the directives that are used to bind the application data to the attributes of DOM elements such as ng-disabled, ng- show, ng-hide, ng-click. Furthermore, if you have any query, feel free to share with us, surely we will get back to you!

Introduction to AngularJS HTML DOM
Show Buttons
Hide Buttons