Introduction to some common instructions in Angularjs

Source: Internet
Author: User
Tags locale min


This article mainly introduces the collation of some of the common Angularjs, including Ng-app, Ng-init, Ng-model and ng-repeat of the four instructions, friends can refer to the following



The ANGULARJS directive is used to extend HTML. These are the special attributes from the ng-prefix first. We will discuss the following instructions:



Ng-app-This instruction initiates a ANGULARJS application.



Ng-init-This instruction initializes the application data.



Ng-model-this directive defines the model that the variable is used in Angularjs.



Ng-repeat-the directive will repeat the HTML element for each item in the collection.



Ng-app directives



Ng-app command to start a ANGULARJS application. It defines the root element. It automatically initializes or launches the application that loads the Web page containing the ANGULARJS application. It is also used to load various ANGULARJS modules ANGULARJS applications. In the following example, we define the default ANGULARJS application using the Ng-app attribute of the DIV element.




<div ng-app="">
...
</div>



Ng-init directives



The ng-init instruction initializes the data for a ANGULARJS application. A variable that is used to put a value in an application. In the following example, we will initialize the countries array. Use the JSON syntax to define the countries array.




<div ng-app=""ng-init="countries=[{locale:'en-US',name:'United States'},
                  {locale:'en-GB',name:'United Kingdom'},
                  {locale:'en-FR',name:'France'}]">
      
...
</div>



Ng-model directives



The Ng-model directive defines the model/variable that is used in the ANGULARJS application. In the following example, we define a model named "name".



<div ng-app="">
...
<p>Enter your Name: <input type="text"ng-model="name"></p>
</div>



Ng-repeat directives



The ng-repeat instruction repeats each item in the collection of HTML elements. In the following example, we have iterated the array countries.




<div ng-app="">
...
  <p>List of Countrieswithlocale:</p>
  <ol>
   <li ng-repeat="country in countries">
     {{'Country: '+ country.name +', Locale: '+ country.locale }}
   </li>
  </ol>
</div>



Example



The following example shows all of the above instructions.



Testangularjs.html




<html>
<title>AngularJS Directives</title>
<body>
<h1>Sample Application</h1>
<div ng-app=""ng-init="countries=[{locale:'en-US',name:'United States'},
                  {locale:'en-GB',name:'United Kingdom'},
                  {locale:'en-FR',name:'France'}]">
  <p>Enter your Name: <input type="text"ng-model="name"></p>
  <p>Hello <span ng-bind="name"></span>!</p>
  <p>List of Countrieswithlocale:</p>
  <ol>
   <li ng-repeat="country in countries">
     {{'Country: '+ country.name +', Locale: '+ country.locale }}
   </li>
  </ol>
</div>
</body>
</html>



Output



Open textangularjs.html in a Web browser. Enter a name and see the following results.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.