2013-03-18 84 views
0

我的代码的一部分,就像这样:angularjs,NG-重复和DOM元素大小

<div class="wrapper-directive"> 
    <div class="table" style="display:table"> 
     <div class="column" style="display:table-cell;" ng-repeat="column in columns"> 
     {{column.text}}</div> 
     </div> 
    </div> 

我怎样才能得到“wrapperDirective”重复“列”元素的宽度是多少? 我的理解,我需要像onDomRepeatComplete事件,但在这一刻,我仍然无法找到正确的解决方案和语法在仅使用setTimeout的停顿......

回答

1

$last可以用来确定当最后< DIV>正在创建。见this fiddle(我没有写它)的checkLast指令的实现,你可以连接到您的< div>元素:

directive('checkLast', function() { 
    return function (scope, element, attrs) { 
    if (scope.$last === true) { 
     element.ready(function() { 
      // determine width here using jQuery or JavaScript 
      // If that doesn't work try with $timeout: 
      // $timeout(function() { 
      // ... 
      //}, 0, false); // remove false if you need $apply to run 

参见https://stackoverflow.com/a/13906907/215945

+0

谢谢,这正是我寻找 – sarjick 2013-03-18 20:32:20

+1

将@sarjick标记为公认的答案会很好。 – boatcoder 2014-01-16 03:48:20