首页 > 其他 > 详细

angular第五天

时间:2016-10-15 13:34:06      阅读:213      评论:0      收藏:0      [点我收藏+]

1、$filter

2、自定义过滤器

<!-- index.html -->
<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="angular.js"></script>
</head>
<body>
    <div ng-controller="firstController">
        <p>{{ name }}</p>
        <p>{{ num }}</p>
    </div>
</body>
<script type="text/javascript">
    var app = angular.module("myApp", []);
    app.controller(‘firstController‘, [‘$scope‘,‘$filter‘, function($scope, $filter){
   
        $scope.num = 344342342357.32342565;
        $scope.name = $filter("firstUpper")("hello");
    }]);

    //自定义过滤器的写法是返回一个函数
    app.filter("firstUpper",function(){
        //这里的参数就是使用过滤器的时候传入的参数
        return function(str,num,nu2){
            // console.log(str);
            // console.log(num);
            // console.log(nu2);
            return str.charAt(0).toUpperCase()+str.substring(1);
        }
    })
</script>
</html>

 

angular第五天

原文:http://www.cnblogs.com/gao-xiong/p/5963038.html

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