Directive is the most important part of all AngularJS applications. Although AngularJS already provides a rich set of commands, you often need to create application-specific commands. This tutorial will show you how to customize commands and how to use them in real projects. AngularJS extends HTML attributes by using commands.
AngularJS commands
AngularJS commands are extended HTML attributes with a ng-prefix.
The ng-app command is used to initialize AngularJS application.
The ng-init command is used to initialize application data.
The ng-model command is used to bind the values of HTML controls (such as input, select, and textarea) to application data.
Name:
You wrote: {{ firstName }}
The ng-app command also tells AngularJS that
The element is the root element of AngularJS application, that is, the scope.
Data Binding
In the preceding example, {firstName} is an AngularJS data binding expression.
In AngularJS data binding, AngularJS expressions use AngularJS data for Synchronous updates.
{FirstName} synchronously updates data through ng-model = "firstName.
Quantity: Costs: Total in dollar: {{ quantity * price }}
Note uses the ng-init command in AngularJS development. In the controller section, you will see better data initialization methods.
Repeat HTML elements
The ng-repeat command is used to repeatedly create an HTML element:
Use the ng-repeat command on the object array:
- {{ x.name + ', ' + x.country }}
Note AngularJS is very suitable for database CRUD (that is, create, read, update, and delete) operations. Imagine what if these objects come from databases?
Ng-app command
The ng-app directive defines the root element of AngularJS application.
After the Web page is loaded, the ng-app command automatically initializes the application. That is, it automatically initializes and directs AngularJS application to execute.
In the subsequent sections, you will learn how to specify a value for the ng-app command (for example, ng-app = "myModule") to associate with the module.
Ng-init command
The ng-init command is used to initialize the value of AngularJS application.
Generally, the ng-init command is not required, but the Controller or module is used for initialization.
In the following sections, you will learn about controllers and modules.
Ng-model command
The ng-model command is used to bind the values of HTML controls (such as input, select, and textarea) to application data.
The ng-model command can also be used:
Provide data verification (such as verification numbers, email addresses, required ).
Provide the status of the data (such as invalid, dirty, touched, error ).
Provides CSS style classes for HTML elements.
Binds HTML elements to HTML forms.
Ng-repeat command
The ng-repeat command is used to generate an HTML element for each element in a data set (OR array.
The above is all the content of this article. I hope you will like it.