2015-12-17 24 views
0

我使用dotdotdot似乎是一个很酷的插件...但是,我需要使用它的角度,不工作,如果新元素加载(通过http.get <> ng-repeat)...如何使用角点dotdotdot?

所以我发现有一个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 }); 

如何用角度使用它呢?

在他们documentation

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

模板:

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

但是如何设置选项?

回答

0

它看起来不像你可以。这是该指令的源代码,从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()

你可能会想要分叉或只写自己的。

+0

我得到了上述错误代码TypeError:element.dotdotdot不是函数 – Monasha