ng-repeat
ネストされたレンダリングが完了した後に実行されるディレクティブを構築しようとしています。これが私が試したことです(フィドル):
HTML:
<div ng-app="MyApp" ng-controller="MyCtrl">
<ul my-directive>
<li ng-repeat="animal in animals">{{animal}}</li>
</ul>
</div>
そして JavaScript:
angular.module("MyApp", [])
.directive("myDirective", function () {
return function(scope, element, attrs) {
alert(element.find("li").length); // 0
};
});
function MyCtrl($scope) {
$scope.animals = ["Dog", "Cat", "Elephant"];
}
カスタム ディレクティブのリンク関数は、すべての<li>
要素がレンダリングされる前に実行されます (そして0
警告が表示されます)。ng-repeat
レンダリングが完了した後にコードを実行するにはどうすればよいですか?