Detailed explanation of the use of angular's scopel directive

php中世界最好的语言
Release: 2018-03-12 16:59:04
Original
1529 people have browsed it

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

  Document 
 
Copy after login


Detailed explanation of the use of angulars scopel directive

##It’s really good to use a custom directive like the above, but if If you want to customize the buttons rendered by each command, it seems that it is not possible. For example, below we create a bunch of custom commands, and they look exactly the same:

  Document 
 
Copy after login


Detailed explanation of the use of angulars scopel 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:

  Document 
 
Copy after login

Detailed explanation of the use of angulars scopel directiveIt’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:

  Document 
 
Copy after login

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:

  Document 
 
Copy after login

Of course, the = sign above is two-way data binding:

  Document 
 
Copy after login

If you only want one-way data communication, you can use the @ symbol:

  Document 
 
Copy after login

If you want to use ng-class, you can do it:

  Document 
 
Copy after login

Finally, there is a scope that can be set to refer to the external scope method

  Document 
 
Copy after login

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 vertically

The 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!