angularJS: dotdotdot for overflow text and performance

后端 未结 4 921
暖寄归人
暖寄归人 2021-01-07 01:31

I\'m new to angularJS and maybe have written something bad...

but how could i right implement this plugin: https://github.com/BeSite/jQuery.dotdotdot

on my t

4条回答
  •  独厮守ぢ
    2021-01-07 01:56

    Here's my attempt:

    • Adds an expression to the $watch call to improve performance
    • Removes { watch: true } option which needlessly polls

    Directive:

    app.directive('dotdotdot', ['$timeout', function($timeout) {
        return {
            restrict: 'A',
            link: function(scope, element, attributes) {
    
                scope.$watch(attributes.dotdotdot, function() {
    
                    // Wait for DOM to render
                    $timeout(function() {
                        element.dotdotdot();
                    }, 400);
                });
            }
        }
    }]);
    

    Template:

    {{article.Title}}

提交回复
热议问题