コンテンツをグリッドとして再配置するカスタム ディレクティブを構築しようとしています。ng-repeat
ディレクティブの結果をトランスクルージョンしてから、結果の要素を並べ替えたいと考えています。
問題はelement.children()
、リンク関数内でメソッドを呼び出すと、ng-repeat
ディレクティブがまだレンダリングされておらず、コメントとして解釈されるため、空の配列があることです。
それ以外の場合、その内容が「静的」である場合、ディレクティブはうまく機能します。
HTML
<grid n='6'>
<div ng-repeat="i in [1,2,3]"></div>
</grid>
興味深いコードのみを含む私のディレクティブ:
app.directive('grid', [function () {
return {
restrict: 'E',
replace: true,
transclude: true,
template: "<div ng-transclude></div>",
link: function (scope, grid, attrs) {
// With an ngRepeat transcluded, els result in an empty array
var els = grid.children();
// ...
};
}]);
何が欠けていますか?