2015-12-17 51 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