Angular2 OrderBy and Filter Pipes

Angular2 seems to include a lot of the real life lessons learned from AngularJs (aka Angular1). That is great. However, it feels to me that sometimes the Angular team, with the best intentions, took a purist view. They have the right reasoning, they want to protect us (the developers) from ourselves, but the outcome is that simple things are no longer simple.

Here is a specific example for that:

The ability to filter and sort array of elements in the Angular view code without too many lines of codes.

In Angular1 we could have done the following:

<li ng-repeat=”emp in employees | orderBy : ‘office-number’”>{{emp.full_name}}</li>

(See more complex snippet here).

That option of doing an oderBy on the fly in the view was wonderful. It did come in a price as the Angular engine made the determination of when to run the orderBy, there were many cases that this expensive sort operation was executed an insane amount of times slowing down the entire page. So i really do get what the Angular team was trying to do. But still…it is annoying that this can’t be done this way anymore. I now have to write code somewhere else to implement what should have been part of the platform.

See more of the details about Pipes in Angular2:

https://angular.io/docs/ts/latest/guide/pipes.html

Also see more about the explicit decision not to include these functions:

https://angular.io/docs/ts/latest/guide/pipes.html#!#no-filter-pipe

Advertisements

Author: dave

Consider myself kid in soul and naive by choice. I am interested in people, technology and business and thrive when they all work together. My favorite quote and motto is that “You can fool some people some times but you cant fool all the people all the time” ― Bob Marley

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s