angularディレクティブでjqueryプラグインを初期化したいのですが、サービスデータが返され、DOMで最初のレンダラーが返された後でのみです。angularディレクティブでこれを行う方法を理解しているようです。私はこれまでのところこのコードを持っていますが、サービスデータが到着した後、DOM のレンダラーになる前にプラグインを呼び出しているようです...何かヒントはありますか?
myApp.directive('myDirective', function () {
return {
restrict: 'A',
link: function ($scope, element, attrs) {
$scope.$watch("data.length", function( newValue, oldValue ) {
if ( newValue === oldValue ) {
console.log( "Should return..." );
return;
}
$(element).elastislide();
});
}
};
});
=== 編集 ==== setTimeout 関数を使用して実行を延期すると、機能しますが、これは正しい方法ですか?
myApp.directive('myDirective', function () {
return {
restrict: 'A',
link: function ($scope, element, attrs) {
$scope.$watch("data.length", function( newValue, oldValue ) {
if ( newValue === oldValue ) {
console.log( "Should return..." );
return;
}
postpone = $timeout(function() {
$('#carousel').elastislide();
}, 100);
});
}
};
});