加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS中内置过滤器问题?

发布时间:2020-12-17 10:07:39 所属栏目:安全 来源:网络整理
导读:实在学习AngularJS过滤器中遇到的问题 这个是页面代码 !DOCTYPE html html head meta charset= "utf-8" / title / title / head body ng-app= "myApp" div ng-controller= "ctrl01" h1 {{ money | currency:' ¥ ' }} / h1 h1 {{ birthday | date :'yyyy 年

实在学习AngularJS过滤器中遇到的问题

这个是页面代码

<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8" />
      <title></title>
      
   </head>
   <body  ng-app="myApp"  >
      
      
      <div ng-controller="ctrl01" >
         
         <h1>{{money | currency:''  }}</h1>
         <h1>{{birthday | date:'yyyyMMdd' }}</h1>
         
         
         <input ng-model="condition"  />
         <br />
         <input type="text" ng-model="cond_name" />
         <div  ng-repeat="user in ( users | filter:{name:cond_name} ) ">
               {{user.name}}--{{user.phone}}
         </div>
         
            <hr />
         
         <div  ng-repeat="user in ( users | filter:func ) ">
               {{user.name}}--{{user.phone}}
         </div>
         <hr />

         <div  ng-repeat="user in ( users | filter:condition ) ">
            {{user.name}}--{{user.phone}}
         </div>
         
      </div>

   </body>
   <script type="text/javascript" src="js/angular.min.js" ></script>
   <script type="text/javascript" src="js/filter_app.js" ></script>
   
</html>

这个是 filter_app.js 的代码
angular.module("myApp",[])
         .controller("ctrl01",function($scope,$rootScope){
         
            $scope.money=123222221;
            $scope.birthday= new Date();
            
            var  users=[
               {id:1,name:'cai10',phone:'456789',age:3},{id:2,name:'xiaogao2',phone:'12312ma3',age:5},{id:3,name:'laogao3',phone:'123123',age:7},{id:4,name:'laoma4',age:8},];
            
            $scope.users=users;
            $scope.cond_name="";
            
            
            $scope.func=function(user){
               
               return  user.age>3;
            }
         });
         

这是一个字符串过滤,当我输入4的时候,过滤结果是正确的

当我输入的是7的时候,第2个结果是怎么出来的,明显第二个中没有7怎么会被过滤出来的?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读