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

查看:30
本文介绍了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}">

当我在文本框中输入一个值时,结果会被过滤.当我删除输入值时,所有电影都会显示.到现在为止还挺好.但是当页面(或视图)第一次加载时,过滤器不返回任何元素并且表格是空的.在我看来,过滤器要么没有正确调用,要么值错误.任何建议将不胜感激.

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天全站免登陆