Serge Serge - 1 year ago 141
AngularJS Question

Filter in angular ng-init

I try to initialise a collection in the

. Why this code does not work?

<div ng-app="myApp" ng-controller="PeopleCtrl">
<ul ng-init="myPeople=(people|filter:{show:true})" ng-repeat="person in myPeople">
<li>{{}}, {{}}


I don't need using
or other things, I just wonder if possible to initialise a collection using a filter in

Answer Source

ng-init would not work when data is coming asynchronously, and I don't think so ng-init suits your case.

I'd suggest you to use alias for filtered data in ng-repeat itself, while filtering myPeople collection

ng-repeat="person in people|filter:{show:true} as myPeople"