directives in angularJs

Names of AngularJs directives starts with "ng-" prefix. Directives are nothing but HTML attributes extended with "ng-" prefix.

There are three main basic directives that every Angular developer must know

  • ng-app 
    Initialize an AngularJs application
  • ng-init 
    Initialize application data
  • ng-model 
    Binds the value of HTML controls such as input, select, textarea to application data.
Here is a simple example of usage of These three directives

<!DOCTYPE html>

<html>
 <head>
  <script src="scripts/angular.min.js"></script> 
 </head>
 <body ng-app="">
  <div  ng-init="firstName='name'">
   <p>Name: <input type="text" ng-model="firstName"></p>
   <p>Welcome : {{ firstName }}</p>
  </div>
 </body>
</html>

Here is a live demo. try it


Live Demo
Name:
Welcome : {{ firstName }}

No comments:

Post a Comment