过滤器:angularjs 中的 notarray 错误 [英] filter: notarray error in angularjs

查看:23
本文介绍了过滤器:angularjs 中的 notarray 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://plnkr.co/edit/cJsScs8ixF1aq85Ri7nV?p=preview

过滤器不起作用.代码的其他部分也中断了.抛出错误过滤器:notarray.如何修复它

<link rel="stylesheet" href="style.css"><body ng-init="items=[3,1,2,3];"><h1>你好,Plunker!</h1><div >

<input type="text" ng-model="nm"/><div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide">{{物品}}

<button ng-click="hide=!hide">切换 </button><button ng-click="items[items.length]=items.length">添加</button><script src="https://code.angularjs.org/1.4.2/angular.min.js"></script><script src="script.js"></script></html>

解决方案

ng-repeat 说:

<块引用>

track by 必须始终是最后一个表达式

所以你需要改变这一行:

到此:

我知道这很晦涩难懂,而这个很容易让人认出.文档通常不在您期望的页面上(例如过滤器),但仍位于合乎逻辑的位置(例如 ng-repeat).它应该"都在那里.

http://plnkr.co/edit/cJsScs8ixF1aq85Ri7nV?p=preview

filter is not working. Other part of code also breaks. Throwing error filter:notarray. how it can be fixed

<head>
  <link rel="stylesheet" href="style.css">

</head>

<body ng-init="items=[3,1,2,3];">
  <h1>Hello Plunker!</h1>

  <div >

  </div>
  <input type="text" ng-model="nm" />



  <div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide">
    {{item}}

  </div>

  <button ng-click="hide=!hide">Toggle </button>
  <button ng-click="items[items.length]=items.length">Add</button>


  <script src="https://code.angularjs.org/1.4.2/angular.min.js"></script>
  <script src="script.js"></script>
</body>

</html>

解决方案

The documentation for ng-repeat says:

track by must always be the last expression

So you need to change this line:

<div ng-repeat="item in items track by $index | filter:nm" ng-hide="hide">

to this:

<div ng-repeat="item in items | filter: nm track by $index" ng-hide="hide">

I know it's obscure, and this one catches people out. Often the documentation isn't on the page you expect it to be (e.g. filter) but is still in a logical place (e.g. ng-repeat). It 'should' all be there.

这篇关于过滤器:angularjs 中的 notarray 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆