输入字段过滤器在AngularJS中不起作用

h

这个小提琴中,我已经成功实现了几乎所有类型的过滤器

<div data-ng-app='' data-ng-init="vehicles=[
                   {type:'car',color:'red'},
                   {type:'bike',color:'black'}]">
  <h1>
        AngularJS <a href='http://www.w3schools.com/angular/angular_filters.asp'>
        Filters Example</a>
    </h1>

  <p>Enter text
    <input type='text' data-ng-model='abc' />
  </p>
  <p>The text you entered is
    <br/> <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_uppercase'>Upper case</a> {{ abc | uppercase }}
    <br/><a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_lowercase'>Lower case</a> {{ abc | lowercase }}</p>Enter amount
  <input type='number' data-ng-model='num1' />
  <p>The <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_currency'>amount</a> you entered is
    <br/>{{ num1 | currency }}</p> <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_orderby'> Directives Filter example</a>

  <br/>Vehicles filtered by type:
  <ul data-ng-repeat="v in vehicles | orderBy:'type'">
    <li>{{"Vehicle type is "+v.type +" with color "+ v.color}}</li>
  </ul>
  <br/>Vehicles <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_input'>filtered by user input:</a>

  <br/>
  <input type="text" ng-model='test' />
  <ul data-ng-repeat="v in vehicles | filter: 'test' | orderBy:'type'">
    <li>{{"Vehicle type is "+v.type +" with color "+ v.color}}</li>
  </ul>
</div>

除了输入过滤器,其他所有东西都在工作

这就是我现在所看到的

没有输出

为什么不通过用户输入来打印和过滤数组?

维维克

删除'test'传递给过滤器的单引号由于它不是字符串,因此它是一个模型,应该直接传递给过滤器。

<ul data-ng-repeat="v in vehicles | filter: test | orderBy:'type'">
    <li>{{"Vehicle type is "+v.type +" with color "+ v.color}}</li>
</ul>

上面的代码将起作用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章