Home > Web Front-end > JS Tutorial > body text

Can you use angularjs filters? Let's look at the detailed explanation of angularjs filters

寻∝梦
Release: 2018-09-07 11:53:23
Original
1229 people have browsed it

The filter in

angularjs is something we often use, but our understanding of it is only at the level of being able to use it. Let’s learn more about angularjs filters this time. Let’s take a look at this article

Using filters in Controller

Disadvantages of using filters in DOM

When we use filters, more The pipe symbol (|) is used in DOM to filter, because it is simple. But behind its simplicity, performance is sacrificed. Filters in DOM will cause additional internal overhead, so using filters in Controller will be faster.

But some people will say: I don’t feel the difference. This is because you are not filtering enough objects.

For example, we sometimes use filters for ng-repeat. At this time, when there are thousands of data in the input array, we can clearly see that when loading the page, become slow.

Difference

So what is the difference between using filters in Controller and using them in DOM?

This is because ngRepeat will be called once in each $digest loop. Since angular has a dirty check mechanism, no matter what operation is performed, the internal $watch() will be rechecked, and each action may change. Array collection, so a filter must be executed after each $digest. (If you want to learn more about angularjs, go to the PHP Chinese website angularjs Reference Manual column to learn)

Can you use angularjs filters? Lets look at the detailed explanation of angularjs filters

in Calling filters in Controller is different. We can limit the operations after which the filter is executed, thus reducing unnecessary consumption.

Can you use angularjs filters? Lets look at the detailed explanation of angularjs filters

Suggestion

In addition, the filter is to give it an input, and then it gives you an output. In fact, the principle is a function. However, through the above analysis, the execution of the filter is unique, so do not use overly complex logic code in the filter, which will slow down the application.

When complex logic needs to be executed, it is better to abstract it into a Service.

Summary

In angularjs, the filter is relatively simple, but it is quite interesting to study it carefully. If you haven’t seen enough yet, I recommend the angularjs Learning Manual column on the PHP Chinese website. There is a lot more angularjs knowledge you need to learn there.

【Editor’s Recommendation】

How much do you know about angularjs performance optimization? Here is the detailed angularjs performance optimization process

#How to use expressions in angularjs? Examples of using expressions in angularjs


The above is the detailed content of Can you use angularjs filters? Let's look at the detailed explanation of angularjs filters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
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
Popular Tutorials
More>
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!