2014-04-04 46 views
0

好basicly正如標題所說寬度...角打印元素高度和NG-重複

<td data-ng-repeat="j in [0,1,2,3,4,5,6,7,8,9,10]"> 
    Height:{{this.height}}, Width:{{this.width}} 
</td> 

this參考$範圍,而不是<td>本身。

回答

1

嘗試指令的方法,也許這樣?將html更改爲

<td data-ng-repeat="j in [0,1,2,3,4,5,6,7,8,9,10]" dimensions> 
    Height:{{height}}, Width:{{width}} 
</td> 

.directive('dimensions', function() { 
    return { 
     link: function(scope, elem) { 
      scope.height = elem[0].offsetHeight; 
      scope.width = elem[0].offsetWidth; 
     } 
    } 
}); 
+0

什麼是指令附加到app? (app = angular.module('studentApp',['ngRoute']);)如果爲true,我猜這種方法無效[link](https://student.sps-prosek.cz/~eisead11it/web/ IS /學生/#/) – Akxe

+1

在Zack的例子中有一個函數()太多,否則它工作正常:http://plnkr.co/edit/peoIK9Ucxj3OBm17EMkH?p=preview – tasseKATT

+0

這種方法不是動態的... – Akxe