AngularJs 服务-$filter

本文介绍了AngularJS中的几个重要内置服务,包括$location、$timeout、$interval、$filter、$log及$http等,通过实例展示了如何使用这些服务来增强应用功能。特别关注了$filters服务,演示了如何在控制器中利用过滤器格式化数据。
<!DOCTYPE html>  
<html lang="en" ng-app="App">  
<head>  
    <meta charset="UTF-8">  
    <title>$filter 服务</title>  
</head>  
<!--  
    服务:服务是一个对象或函数,对外提供特定的功能.  
    内建服务:  
        1: $location是对原生Javascript中location对象属性和方法的封装。  
        2: $timeout&$interval对原生Javascript中的setTimeout和setInterval进行了封装。  
        3: $filter在控制器中格式化数据。  
        4: $log打印调试信息  
        5: $http用于向服务端发起异步请求。  
        6: 同时还支持多种快捷方式如$http.get()、$http.post()、$http.jsonp。  
-->  
<body>  
    <ul ng-controller="DemoController">  
        <li>价格: {{price}}</li>  
        <li>大写:{{str}}</li>  
        <li>截取: {{str1}}</li>  
    </ul>  
    <script src="../libs/angular.min.js"></script>  
    <script>  
      
        var App = angular.module('App', []);  
  
        // $filter是过滤器  
        App.controller('DemoController', ['$scope', '$filter', function ($scope, $filter) {  
  
            // $filter是九种过滤器中任何一个  
            $scope.price = 11.11;  
            var currency = $filter('currency');  
            $scope.price = currency($scope.price);  
  
            $scope.str = 'hello angular';  
            var uppercase = $filter('uppercase');  
            $scope.str = uppercase($scope.str);  
  
            $scope.str1 = $filter('limitTo')($scope.str, 2);  
  
        }]);  
  
    </script>  
  
</body>  
</html>  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值