角过滤器 - 与controllerAs语法不工作 [英] Angular filter - with controllerAs syntax not working

查看:121
本文介绍了角过滤器 - 与controllerAs语法不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的HTML中的code:

I have this in html code:

<md-list>
  <md-list-item ng-repeat="schema in dash.filteredSchemas = (dash.items | filter: {name: dash.schemaListFilter}) | orderBy: 'schema.id'">
    <h4>{{ ::schema.name }}</h4>
  </md-list-item>
</md-list>
<div ng-show="dash.filteredSchemas.length">Empty</div>

问题是,使用这种语法时,我没有看到任何结果 - 在那里,如果过滤器未填写10个结果应该显示。

The problem is that I don't see any results when using this syntax - where 10 results should be shown if filter in not filled.

注:没有控制台错误。更改为:

Note: no console errors. Changing to:

<md-list>
  <md-list-item ng-repeat="schema in dash.items | filter: {name: dash.schemaListFilter} | orderBy: 'schema.id'">
    <h4>{{ ::schema.name }}</h4>
  </md-list-item>
</md-list>
<div ng-show="dash.filteredSchemas.length">Empty</div> 

显示的结果,但(显然)不显示空消息时应用和过滤器没有结果的比赛。

Shows results but (obviously) not shows the empty message when filter applied and no result match.

什么是错?!

推荐答案

如果你想要得到过滤的结果,但不想打破你可以使用原始数组'为'操作纳克重复 ...

If you want get filtered result but do not want to break original array you can use 'as' operation for ng-repeat...

<md-list>
  <md-list-item ng-repeat="schema in dash.items | filter: {name: dash.schemaListFilter} | orderBy: 'schema.id' as filteredData">
    <h4>{{ ::schema.name }}</h4>
  </md-list-item>
</md-list>
<div ng-show="filteredData.length">Empty</div>

所以每当你改变你的过滤器的查询结果将被设置为'filteredData这样你就可以使用这个数组属性来实现你想要的...

so whenever you change your filter query the result will be set to 'filteredData' so you can use this array properties to achieve what you want...

这篇关于角过滤器 - 与controllerAs语法不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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