过滤器使用2

html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<script src="../vendor/angular/angular.js"></script>
<script src="app/index.js"></script>

<body ng-app="myApp">
    <div ng-controller="testController">
        {{data.message | lowercase}}
        <p>{{[1,2,3,45,3,2] | limitTo:3}}</p>
        <p>{{[1,2,3,45,3,2] | limitTo:-2}}</p>
        <p>
            {{data.city | filter:'上海'}}
        </p>
        <p>
            {{data.city | filter:{ py:'g'} }}}
        </p>
        <p>
            过绿: {{data.city | filter:checkName }}}
        </p>
        <p>
            {{data.city | orderBy:'name' }}
        </p>
        <p>
            {{data.city | orderBy:'-name' }}
        </p>
    </div>
</body>

</html>

js:

var app = angular.module('myApp', []);
app.factory('Data', function() {

    return {
        message: "Hello  word!",
        city: [{
                name: "上海",
                py: "shanghai"
            },
            {
                name: "北京",
                py: "beijing"
            },
            {
                name: "四川",
                py: "sichuan"
            }
        ]
    }
})
app.controller('testController', function($scope, Data, $filter) {
    $scope.data = Data;
    var number = $filter('number')(3000);
    console.log(number, "数字");

    var jsonString = $filter('json')($scope.data);
    console.log(jsonString);


    $scope.checkName = function(obj) {
        console.log(obj);

        if (obj.py.indexOf('h') === -1)
            return false;
        return true;
    }
})

效果图:
过滤器使用2

上一篇:jQuery UI dialog 參数说明


下一篇:第十二周周记