2015-02-06 70 views
0

我有這樣的代碼dotdotdot插件分析的角度表達了評估之前

<div ng-app="m" ng-controller="a"> 
     <div d style="width:100px;height:200px" > 
      {{customer.name}} 
      <p>Lorem Ipsum is simply dummy text. Lorem Ipsum is simply dummy textLorem Ipsum is simply dummy textLorem Ipsum is simply dummy textLorem Ipsum is simply dummy textLorem Ipsum is simply dummy textLorem Ipsum is simply dummy text</p> 
     </div> 
    </div> 

這裏是JS代碼

var b = angular.module('m', []).controller('a', function ($scope) { 
    $scope.customer = { 
     name: 'Aby' 
    } }); b.directive('d', function() { 
    return { 
     retistric: 'A', 
     link: function ($scope, element, attributes) { 
      $(element).dotdotdot({ 
       /* The text to add as ellipsis. */ 
       'ellipsis': '... ', 

       /* jQuery-selector for the element to keep and put after the ellipsis. */ 
       'after': null, 

       /* Whether to update the ellipsis: true/'window' */ 
       'watch': true, 

       /* Optionally set a max-height, if null, the height will be measured. */ 
       'height': null, 

       /* Callback function that is fired after the ellipsis is added, 
        receives two parameters: isTruncated(boolean), orgContent(string). */ 
       'callback': attributes["callback"], 
      }); 

     } 
    }; 
    }); 

這裏是出放

{{customer.name}} Lorem Ipsum is simply dummy text. Lorem Ipsum is simply dummy textLorem Ipsum is... 

這裏dotdotdot呼叫看到作爲字符串的angularjs表達式。我如何確保在插件執行之前評估表達式?

回答

0

嘗試更改鏈接以在指令中編譯。

var b = angular.module('m', []).controller('a', function ($scope) { 
    $scope.customer = { 
    name: 'Aby' 
    } }); b.directive('d', function() { 
    return { 
    retistric: 'A', 
    compile: function (element, attributes) { 
     return { 
     post: function ($scope, element) { 
      $(element).dotdotdot({ 
      /* The text to add as ellipsis. */ 
      'ellipsis': '... ', 

      /* jQuery-selector for the element to keep and put after the ellipsis. */ 
      'after': null, 

      /* Whether to update the ellipsis: true/'window' */ 
      'watch': true, 

      /* Optionally set a max-height, if null, the height will be measured. */ 
      'height': null, 

      /* Callback function that is fired after the ellipsis is added, 
      receives two parameters: isTruncated(boolean), orgContent(string). */ 
      'callback': attributes["callback"] 
      }); 
     } 
     } 
    } 
    } 
});