ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

过滤器使用2

2021-10-14 22:06:44  阅读:72  来源: 互联网

标签:city name py filter 使用 过滤器 scope data


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;
    }
})

效果图:
在这里插入图片描述

标签:city,name,py,filter,使用,过滤器,scope,data
来源: https://blog.csdn.net/weixin_45932157/article/details/120773645

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有