4 ms·
A good example is where I have a list of items which is filtered by a select[1]. I have the select wired up to the controller with a two-way binding and the con
by ollysb 13y ago
A good example is where I have a list of items which is filtered by a select[1]. I have the select wired up to the controller with a two-way binding and the controller watches for changes to the binding and filters the list accordingly. Maybe this isn't an idiomatic way to do it?
[1] http://plnkr.co/edit/ykfblPHlwkBJyMeObFyV?p=preview http://plnkr.co/edit/ykfblPHlwkBJyMeObFyV?p=preview
- olegbl 13y agoHere's your example without a watch: http://plnkr.co/edit/GCv7bQALiOTgJ0npavwi?p=preview http://plnkr.co/edit/GCv7bQALiOTgJ0npavwi?p=preview
- ollysb 13y agoThat looks interesting, so does the filter reevaluate automatically when any of the variables used in the expression change? edit: and thanks a lot for taking the time to look at it!
- ollysb 13y agoAh, so I see that anything associated to the scope is reavaluated whenever anything else in the scope changes. Here's a further modification based on yours that keeps the criteria on the controller. [1] http://plnkr.co/edit/JYyUvyh30e5L9KwVjDW2?p=preview http://plnkr.co/edit/JYyUvyh30e5L9KwVjDW2?p=preview [2] http://plnkr.co/edit/ffYb14JjgSip5BTITILS?p=preview http://plnkr.co/edit/ffYb14JjgSip5BTITILS?p=preview edit: much happier with this version than the one I started with, thanks edit: added example [2] which doesn't require a watch but still uses the service to do the filtering (because in my app it's actually an ajax call)