This article mainly introduces some common commands in AngularJS, including ng-app, ng-init, ng-model, and ng-repeat, for more information about HTML extensions, see AngularJS commands. These are all special attributes starting with the ng-prefix. We will discuss the following commands:
- Ng-app-this command starts an AngularJS application.
- Ng-init-this command initializes application data.
- Ng-model-the model defined by this directive, which is used by variables in AngularJS.
- Ng-repeat-this command repeats the HTML elements of each project in the set.
Ng-app command
The ng-app command starts an AngularJS application. It defines the root element. It automatically initializes or starts applications that load web pages containing AngularJS applications. It is also used to load AngularJS applications of various AngularJS modules. In the following example, the default AngularJS application uses the ng-app attribute of the p element.
...
Ng-init command
The ng-init command initializes the data of an AngularJS application. It is used to set the variables used in the application. In the following example, the countries array is initialized. Use the JSON syntax to define the countries array.
...
Ng-model command
The ng-model command defines the model/variable used in AngularJS applications. In the following example, we define a model named "name.
...
Enter your Name:
Ng-repeat command
The ng-repeat command repeats every item in the html element set. In the example below, we have iterated the array countries.
...
List of Countries with locale:
- {{ 'Country: ' + country.name + ', Locale: ' + country.locale }}
Example
The following example shows all the preceding commands.
TestAngularJS.html
AngularJS DirectivesSample Application
Enter your Name:
Hello!
List of Countries with locale:
- {'Country: '+ Country. name +', Locale: '+ country. locale }}