AngularJS过滤器返回页面加载空的结果 [英] AngularJS filter returns empty result on page load

查看:230
本文介绍了AngularJS过滤器返回页面加载空的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其值应使用作为过滤器的查询的输入:

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}">

当我输入一个值在文本框中的结果进行过滤。当我删除输入值的所有电影中。到现在为止还挺好。但是,当该页面(或视图)装在第一时间的过滤器没有返回元素表是空的。在我看来,过滤器或者未正确调用或一个错误值。任何意见将是AP preciated。

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.

推荐答案

试试这个

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

我想这是因为查询是在页面加载未定义

I think it is because query is undefined in pageload

这篇关于AngularJS过滤器返回页面加载空的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆