Stupidfrog
Stupidfrog

Reputation: 2102

Angularjs: after using directive for jquery autocomplete, it doesnt work well. Seem got bugs on that

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

Upvotes: 0

Views: 1105

Answers (1)

Langdon
Langdon

Reputation: 20073

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/

Upvotes: 1

Related Questions