官术网_书友最值得收藏!

Introduction

In this chapter, you will learn how to effectively utilize AngularJS filters and services in your applications. Service types are essential tools required for code reuse, abstraction, and resource consumption in your application. Filters, however, are frequently glazed over in introductory courses as they are not considered integral to learning the framework basics. This is a pity as filters let you afford the ability to abstract and compartmentalize large chunks of application functionality cleanly.

All AngularJS filters perform the same class of operations on the data they are passed, but it is easier to think about filters in the context of a pseudo-dichotomy in which there are two kinds: data filters and search filters.

At a very high level, AngularJS data filters are merely tools that modulate JavaScript objects cleanly in the template. On the other half of the spectrum, search filters have the ability to select elements of an enumerable collection that match some of the criteria you have defined. They should be thought of as black box modifiers in your template—well-defined layers of indirection that keep your scopes free of messy data-parsing functions. They both enable your HTML code to be more declarative, and your code to be DRY.

Service types can be thought of as injectable singleton classes to be used throughout your application in order to house the utility functionality and maintain states. The AngularJS service types can appear as values, constants, factories, services, or providers.

Although filters and services are used very differently, a cunning developer can use them both as powerful tools for code abstraction.

主站蜘蛛池模板: 上高县| 富宁县| 台湾省| 祁连县| 江都市| 山阳县| 长海县| 潮州市| 朝阳区| 武威市| 满洲里市| 建宁县| 永顺县| 屯门区| 集贤县| 万安县| 渭源县| 清徐县| 海林市| 金湖县| 南城县| 黄浦区| 来安县| 雷州市| 岗巴县| 江华| 黄梅县| 化州市| 宝兴县| 西城区| 潞城市| 五原县| 砀山县| 江孜县| 宝丰县| 南投市| 凤凰县| 报价| 长顺县| 鄂托克旗| 山西省|