首页 > Web开发 > 详细

[angularjs] angularjs系列笔记(四)过滤器

时间:2016-03-23 00:44:28      阅读:233      评论:0      收藏:0      [点我收藏+]

过滤器可以使用一个管道字符(|)添加到表达式和指令中,这不就是模板函数吗

 

  <body>
    <div ng-app="Home">
      <div ng-controller="Index">
        格式化字符串为小写
        {{myName()|lowercase}}。
        格式化字符串为大写
        {{myName()|uppercase}}。
        格式化数字为货币格式
        {{price|currency}}。
        根据某个表达式排列数组
        <p ng-repeat="x in prices | orderBy:‘price‘">{{x.price}}</p>
        。
        取出数组中的子元素
        <input type="text" ng-model="test">
         <p ng-repeat="x in prices |filter:test | orderBy:‘price‘">{{x.price}}</p></div>
    </div>

  </body>

  <script type="text/javascript">
  //实例化应用对象,参数:模块名,空数组
  var app=angular.module("Home",[]);
  //调用Application对象的controller()方法
  app.controller("Index",function($scope){
    $scope.myName=function(){
      return "Tao"+"ShiHan";
    }
    $scope.price=5;
    $scope.prices=[{price:1},{price:5},{price:3}];
  });
  </script>

 

[angularjs] angularjs系列笔记(四)过滤器

原文:http://www.cnblogs.com/taoshihan/p/5309176.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!