欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Note09--Filter

程序员文章站 2022-06-22 19:53:02
1. 目录结构 2. e.g. a. Filter.html <...

1. 目录结构

Note09--Filter

2. e.g.

a. Filter.html

<html ng-app="MyModule">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <script src="framework/angular-1.3.0.14/angular.js"></script>
        <script src="Filter.js"></script>
    </head>
    <body>
        {{ 1304375948024 | date }}
        <br>
        {{ 1304375948024 | date:"MM/dd/yyyy @ h:mma" }}
        <br>
        {{ 1304375948024 | date:"yyyy-MM-dd hh:mm:ss" }}
        <br>
    </body>
</html>

b. Filter.js

var myModule=angular.module("MyModule",[]);

3. 自定义Filter

a. e.g.

i. MyFilter.html

<html ng-app="MyModule">

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <script src="framework/angular-1.3.0.14/angular.js"></script>
    <script src="MyFilter.js"></script>
</head>

<body>
    {{'大漠穷秋'|filter1 }}
</body>

</html>

ii. MyFilter.js

var myModule=angular.module("MyModule",[]);
myModule.filter('filter1',function(){
    return function(item){
        return item + 'o(∩_∩)o';
    }
});