angularJS: dotdotdot for overflow text and performance

后端 未结 4 931
暖寄归人
暖寄归人 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 02:11

    Template

  • {{movie.title}}
  • Directive

    (function () {
        'use strict';
    
        angular.module('dma.common').directive('dmaDotDotDot', [
            function dmaDotDotDot() {
                return {
                    restrict: 'A',
                    link: function (scope, element, attrs) {
                        scope.$evalAsync(function () {
                            element.dotdotdot({
                                wrap: 'letter'
                            });
                        });
                    }
                };
            }
        ]);
    }());
    

    I tested ng-bind and it doesn't seem to work properly for me. ng-bind hides the content, then fires the dotdotdot(), then compiles the content (Which doesn't work).

    Though this should work—Much better solution than scope.$watch. And I believe it preforms more consistently than the solutions listed without $evalAsync().

    See https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$evalAsync for more information regarding when it fires.

提交回复
热议问题