javascript - Angular text input filter initializes with no results -


i have basic angular app sorts , filters list of species local json file. when app initializes none of species returned. when begin type species returned, , if delete search terms species returned.

i species returned when app initializes.

http://plnkr.co/edit/0dowsvtaepsffwkr8ugs?p=info

i think it's neater use inline notation filter, avoids problem:

<div ng-repeat="animal in species | filter:query | orderby:orderprop")> 

note: can remove code sets $watch on query

edit: want in controller:

the reason filter initialising blank, because $scope.species data being populated asynchronously. when first $watch triggered, there no data filter. stays case until input query.

to solve this, set $watch after data has arrived, so:

$http.get('species.json').success(function(data) {     $scope.species = data;     $scope.$watch('query', function (query) {         $scope.filtereddata = $filter('filter')($scope.species, query);     }); }); 

alternatively manually run filter function once, inside success callback.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -