I want to use Jquery UI's accordion in AngularJS. So i wrote a directive:
angular.module('accordion', [])
.directive('accordion', function () {
return {
restrict: 'AE',
replace: true,
link: function (scope, element, attrs) {
$(document).ready(function () {
setTimeout(function () {
element.accordion({ icons: false });
}, 1000);
});
}
};
});
And I used the setTimeout because the directive is loaded before the page (or is it? I'm not sure), and so I need the timeout for it to be loaded. Of course the timeout is not always sufficient, and sometimes it is too quickly so I can see the HTML before the directive effect it, and then it changes to accordion and I don't want the users to see it.
Ideas?