Home >Web Front-end >JS Tutorial >AngularJS built-in directive_AngularJS
directive, I understand it as a way for AngularJS to operate HTML elements.
Since the first step in learning AngularJS is to write the built-in directive ng-app to indicate that this node is the root node of the application, the directive is already familiar.
This blog briefly records some built-in commands. Let’s use them first, and then talk about some interesting things.
Built-in commands
All built-in instructions are prefixed with ng. It is not recommended for custom instructions to use this prefix to avoid conflicts.
Start with some common built-in commands.
Let’s first list some key built-in instructions, and briefly talk about scope issues.
ng-model
Binding the form control to the properties of the current scope does not seem to be correct.
But don’t worry about the wording for now, it’s easy to understand when used, for example:
ng-init
This directive will initialize the inner scope when called.
This command usually appears in relatively small applications, such as giving a demo or something...
In addition to ng-init, we have more and better options.
ng-app
Every time you use AngularJS, you cannot do without this command. By the way, $rootScope.
The element that declares ng-app will become the starting point of $rootScope, and $rootScope is the root of the scope chain, usually declared in you know.
In other words, all scopes under the root can access it.
However, it is not recommended to overuse $rootScope, otherwise global variables will be everywhere, which will be inefficient and difficult to manage.
Here is an example:
ng-controller
We use this command to install a controller on a DOM element.
A controller? Indeed, it is good to understand it literally, so why do we need a controller?
Remember that in AngularJS 1.2.x, you can define controller like this...
This method is prohibited in AngularJS 1.3.x, because this method will make the controllers fly all over the sky, and it will be impossible to distinguish the levels. Everything is hung on $rootScope...
ng-controller must have an expression as a parameter. In addition, $scope is used to inherit the methods and properties of the superior $scope, including $rootScope.
The following is just a simple example. The ancestor cannot access the scope of the child.
The problem of scope goes beyond that. Let’s put it aside for now and continue to look at other built-in instructions.
ng-form
At first I didn’t understand why there was a form command, but the