This time I will bring you a detailed explanation of the use of angular's scopel instruction. What are the precautions for using angular's scopel instruction? The following is a practical case, let's take a look.
Let’s create a custom directive
##One idea is to put these custom command buttons in different controllers, and then pass different values through the $scope context in the controller:
It’s too troublesome to write like this, so our angular provides a configuration item called scope for our custom instructions, so we can write it like this:
To understand the above, just pay attention to two points:
The a in the independent scope here represents the model a in the template
=b represents that Angular needs to find the view. The attribute b of the current directive
The value of attribute b needs to be found in the external scope
If you want to bind the name of the model in the directive scope and the attributes when used externally The names are the same and can be written as follows:
Of course, the = sign above is two-way data binding:
If you only want one-way data communication, you can use the @ symbol:
If you want to use ng-class, you can do it:
Finally, there is a scope that can be set to refer to the external scope method
I believe you have read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Detailed explanation of the use of Angular Material What are the naming rules for id selectors in css Unpopular method of centering elements horizontally and verticallyThe above is the detailed content of Detailed explanation of the use of angular's scopel directive. For more information, please follow other related articles on the PHP Chinese website!