码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-03-23 00:46:50      阅读:134      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!