AngularJS filter returns empty result on page load

为君一笑 提交于 2019-12-11 04:15:02

问题


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.


回答1:


try this

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

I think it is because query is undefined in pageload



来源:https://stackoverflow.com/questions/28118290/angularjs-filter-returns-empty-result-on-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!