0

I am writing a simple tabs application, I used angular js directive to to call the jquery tabs plugin, but the view is not updated properly and I do not see the tabs.

http://jsbin.com/UDIHOTIY/1/edit?html

Here is the code snippet. Can someone help me how to render the tabs correctly?

2
  • You have seen the exception right? Line 4: $scope.tabs=data; --- Mixed spaces and tabs. Commented Nov 26, 2013 at 8:05
  • @YagizOzturk this actually should not be a problem in javascript. Commented Nov 26, 2013 at 8:10

1 Answer 1

2

It seems that the DOM is not ready before the directive fires. Using a $timeout works for me:

.directive('hTabs', function($timeout) {
    return {
        restrict: 'A',
        link: function(scope, elm, attrs) {
            $timeout(function(){
                var jqueryElm = $(elm[0]);
                $(jqueryElm).tabs();
            },1000);
        }
    };
});
Sign up to request clarification or add additional context in comments.

2 Comments

setting a timeout in my directive is working. I have one question though, how do I choose the right time out? What is the difference between setting timeout to 0 vs 1000?
Initially I tried with 0 but did not work. Since you 're not firing any https, a delay of 1 - 2 secs should be good I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.