自定义一个过滤器

js代码

function CarouselContentFilter (  ) {
    return function (str) {
        if(str){
            var carContent = '';
            if(str.length >= 50){
                str.length = 50;
                carContent = str.substring(0,50) + '...';
            }
            else {
                carContent = str
            }
            return carContent
        }
    }
}

然后配置过滤器

angular
    .module('jibao')
    .filter('CarouselContentFilter',CarouselContentFilter);

如果想在controller中使用自定义的过滤器,首先在controller中注入过滤器模块名称    如:CarouselContentFilter

html代码

<div class="ani title jb_carousel_content">
    {{img.configXml.content | CarouselContentFilter}}
</div>

 


想要整理更多的碎片知识,扫码关注下面的公众号,让我们在哪里接着唠!

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐