angular限制字符超过一定的字数隐藏字数显示省略号

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuehu837769474/article/details/82109350

自定义一个过滤器

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>

猜你喜欢

转载自blog.csdn.net/xuehu837769474/article/details/82109350