0

as title, when i try to apply autocomplete with angularjs directive. Plugin itself works, however, the rest of the code after directive being initialize, it doesnt work. and does not show any error.

Here is the online test.

http://jsbin.com/ufihip/4

1
  • helps to keep code relevant to problem and remove unrelated code. Be more specific what problems are and streamlining demo would help Commented Mar 25, 2013 at 2:41

1 Answer 1

1

This seems like a hack to me, but I think it's probably fine. It's something I picked up while asking another question here on SO (it was actually a tip from charlieftl).

When you're doing DOM manipulation inside your directives, it's best to do it after everything has initialized (kind of like the ready callback in jQuery). To do this, you can make use of setTimeout or $timeout (which for some reason doesn't work in your example).

Here's the fix to your directive:

myApp.directive('uicomplete', function($http) {
    return function(scope, element, attrs) {
        setTimeout(function() {
            element.autocomplete({
                source: ["ActionScript","AppleScript","Asp"]
            });
        }, 1);
    }
});

And in code: http://jsbin.com/ufihip/7/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.