我具有以下NG-重複AngularJS:截斷多線HTML以ng重複/ NG綁定-HTML結合
<div class="item-post" ng-repeat="item in items">
<div class="item-content" ng-bind-html="item.text"></div>
</div>
其中item.text是多行HTML文本並正確顯示,但我需要將其截斷爲item-post div(250px)的最大高度。然後附加三個點,表示文字較長。
我想使用jquery.autoellipsis這是工作在例如div
與靜態內容。
對於AngularJS我找到了angular-ellipsis,但它不適用於HTML,只能用純文本。我需要在HTML內容上實現它。
在此先感謝您的幫助!
編輯/解決方案:(基於asgoth的答案)
最後,我已經能夠使用jquery.autoellipsis使用自定義指令插件:
myDirectives.directive('htmlEllipsis', ['$timeout', function($timeout) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$timeout(function() {
angular.element(element).ellipsis();
}, 0);
}
};
}]);
而且在局部視圖:
<div class="item-post" ng-repeat="item in items">
<div class="item-content" ng-bind-html="item.text" html-ellipsis></div>
</div>
EDIT2:
從asgoth的回答指導,他的編輯作品運行良好,使用另一種方法比上述指令。
謝謝指導方針已經奏效。我需要稍微修改該指令(添加$ timeout以等待綁定完成)。此外,我已更新此案例的工作解決方案問題。我接受這個答案是因爲它指出了我的正確方向。謝謝! – kamelot
該$超時服務的可惜。我認爲可以通過'element.html()'觀看html內容來實現。 – asgoth
現在效果很好,謝謝! – kamelot