Pragmatick
Pragmatick

Reputation: 130

AngularJS filter returns empty result on page load

I have an input of which the value should be used as a filter query:

<input type="text" ng-model="query" placeholder="Movie title">

and a repeat directive with a filter on a property of the repeated elements:

<tr ng-repeat="movie in movies | filter:{title: query}">

When I enter a value into the text box the results are filtered. When I delete the input value all movies are shown. So far so good. But when the page (or view) is loaded the first time the filter returns no elements and the table is empty. It seems to me that the filter either isn't properly called or with a wrong value. Any advice would be appreciated.

Upvotes: 1

Views: 1261

Answers (1)

maxisam
maxisam

Reputation: 22755

try this

<tr ng-repeat="movie in movies | filter:{title: query||'' }">

I think it is because query is undefined in pageload

Upvotes: 2

Related Questions