【问题标题】:How to use angular-dotdotdot?如何使用角点点?
【发布时间】:2015-12-17 18:14:47
【问题描述】:

我正在使用 dotdotdot 似乎是一个很酷的插件...但是,我需要使用它的角度,如果加载了新元素(通过 http.get ng-repeat)则不起作用...

于是我发现有一个angular-dotdotdot... 怎么用呢?不是很清楚...

假设我有 dotdotdot 的经典用法,如下所示:

// ellipsis body to 4 lines height
var ellipsis = $(".ellipsis-case-body");
var nrLines = 4;
var ellHeight = parseInt(ellipsis.css('line-height'), 10) * nrLines;
ellipsis.dotdotdot({ height: ellHeight });

// ellipsis title to 1 line height
ellipsis = $(".ellipsis-case-title");
nrLines = 1;
ellHeight = parseInt(ellipsis.css('line-height'), 10) * nrLines;
ellipsis.dotdotdot({ height: ellHeight });

angular 怎么用?

在他们的documentation

$scope.myText = 'some really long text';

模板:

<p dotdotdot='myText'>{{myText}}</p>

但是如何设置选项呢?

【问题讨论】:

    标签: javascript angularjs dotdotdot


    【解决方案1】:

    看起来你不能。这是指令源代码,来自 GitHub:

    angular.module('dotdotdot-angular', [])
        .directive('dotdotdot', ['$timeout', function($timeout) {
            return {
                restrict: 'A',
                link: function(scope, element, attributes) {
    
                    // We must pass in the scope binding, e.g. dotdotdot='myText' for scope.myText
                    scope.$watch(attributes.dotdotdot, function() {
    
                        // Wait for DOM to render
                        // NB. Don't use { watch: true } option in dotdotdot as it needlessly polls
                        $timeout(function() {
                            element.dotdotdot();
                        }, 400);
                    });
                }
            }
    }]);
    

    请注意,没有任何内容传递给.dotdotdot()

    你可能想要 fork 这个或者只是写你自己的。

    【讨论】:

    • 上述代码TypeError: element.dotdotdot is not a function 出现此错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 2021-08-31
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    相关资源
    最近更新 更多