Angularjs Directives

Google Advertisements

Prev Tutorial Next Tutorial

Angularjs Directives

A directive is something that introduces new syntax. It improve the feature or functionality of html elements. Directives are markers on a DOM element which attach a special behavior to it. For example, static Html does not know how to create and display a date picker widget. To teach Html this new syntax we need a directive. AngularJS directives are extended Html attributes with the prefix ng-.

Here we discuss following directives;

ng-app

The ng-app directive initializes an AngularJS application. The ng-app directive also tells AngularJS that the <div> element is the "owner" of the AngularJS application. Using this directive you can tell which part of html contains Angularjs app. Below we use ng-app with <div> tag.

Example

<div ng-app="">
Enter text <input type="text" ng-model="name">
<p ng-bind="name"></p>
</div>

Result

Enter text

ng-init

The ng-init directive initialize application data same like variable initialization in C language, In c language you initialize int a=10;.

The ng-init directive initializes an AngularJS Application data. It is used to assign values to the variables.

Example

<div ng-app="" ng-init="name='Porter'"> // initialize name="Porter"
Name: <input type="text" ng-model="name">
<p>name: {{ name }}</p>

ng-model

The ng-model directive binds the value of Html controls (input, select, textarea) to application data. The ng-model directive defines the model/variable to be used in AngularJS Application. In the following example, we define a model named name.

Example

<div data-ng-app="">
1st number <input type="number" ng-model="num1">
2nd number <input type="number" ng-model="num2">
<p><b>Sum:</b> {{num1 + num2}}</p>
</div>

ng-repeat

The ng-repeat directive repeats an Html element. ng-repeat directive repeats a specific element.

Example

<div data-ng-app="" data-ng-init="num=[1, 2, 3]">
 
 <p data-ng-repeat="x in num">
   {{ x }}
 </p>
</div>

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs