javascript
  • html
  • arrays
  • angularjs
  • html5
  • 2015-11-29 48 views 1 likes 
    1

    我已经成功实施几乎所有类型的过滤器this fiddle在AngularJS不工作输入字段过滤器

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

    一切工作除了input filters

    这是我是如何seeing现在:

    no output

    为什么不打印,并通过用户输入过滤阵列?

    回答

    2

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

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

    上述代码将起作用。

    +0

    谢谢@VVK - 所以它澄清说,输入过滤器不需要报价。在这种情况下需要避免的东西吗? – xameeramir

    相关问题