ionic---angular中filter过滤器

首先app.js中依赖声明

angular.module('starter', ['ionic','ngCordova', 'starter.controllers', 'starter.services','starter.directives','starter.filters'])
angular.module('starter.controllers', ['starter.services','starter.directives','starter.filters']);

angular.module('starter.services', ['ngResource', 'starter.config']);

angular.module('starter.directives',[]);

angular.module('starter.filters', []);

filter.js

angular.module('starter.filters')
//状态码转化
.filter('resStatus', function() {
    return function(input) {
        var status = input;
        switch (status){
            case 0:
                status = '订单已完成';
                break;
            case 1:
                status = '商家拒绝接单';
                break;
        }
        return status;
    }
})
//名字过长自动截断
.filter('resName', function() {
    return function(input) {
        var num = input;
        if(num.length>12){
            num = num.substr(0,12)+'....';
        }else{
            num = num;
         }
         return num;
    }
});

页面中使用

<span class="center-y">{{data.type_name | resName : data.type_name}}</span>

你可能感兴趣的:(filter,Cordova,ionic)