自定义过滤器,并传参

<!DOCTYPE html>
<html ng-app='test'>
  <head>
     <meta charset="utf-8">
     <title>angular</title>
     <meta name="viewport" content="width=device-width,initial-scale=1.0,
     maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
     <link rel="stylesheet" type="text/css" href="static/css/reset.css">
     <script src="bower_components/angular/angular.js" charset="utf-8"></script>
     <script >
       var app=angular.module('test',[])
       app.filter('kuaiji',function(){
         return function(input,args){
           alert(input+','+args)
           if (input<0) {
             return '('+(-input)+')'
           }else {
             return input
           }
         }
       })
       app.controller('zhangsan',function($scope,$http){
          $scope.arr=[
            {name:'买早餐',count:3,price:-8},
            {name:'卖出字画',count:5,price:25},
            {name:'请领导吃饭',count:2,price:-250}
          ]
       })
     </script>
 </head>
 <body ng-controller='zhangsan'>
     <ul>
       <li ng-repeat='v in arr'>{{v.name}} 数量:{{v.count}} 支出{{v.count*v.price |kuaiji:'55,yyyy-dd-MM'}}</li>
     </ul>
 </body>
</html>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容