My Blog

My WordPress Blog

My Blog

My WordPress Blog

AngularJS HTML DOM

In AngularJS, some directives can be used to bind application data to attributes of HTML DOM elements.These directives are:

DirectiveDescription
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.

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.

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

    <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>  
      
      lt;button ng-click = "clickCounter = clickCounter + 1">Click Me!</button>  

        Let’s take an example to deploy the all above directives and test the variations:

        See this example:

        <!DOCTYPE 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.3.14/angular.min.js"></script>  
        
        </body>  
        
        </html>
        AngularJS HTML DOM

        Leave a Reply

        Your email address will not be published. Required fields are marked *

        Scroll to top