ui-select2 icon indicating copy to clipboard operation
ui-select2 copied to clipboard

using ui-select2 in directive with isolate scope

Open larryseagull opened this issue 10 years ago • 6 comments

I'm having trouble using ui-select2 in a custom directive with an isolate scope. I am getting this error:

query function not defined for Select2 ...

My select2 options are defined on the controller scope, so I don't have this problem if I make the directive inherit from the controller scope (set scope: true). But I want an isolate scope for the sake of modularity.

larryseagull avatar Oct 19 '13 22:10 larryseagull

I've the same problem if I try to configure on the link function. Any news? Thank you.

juanpujol avatar Nov 13 '13 10:11 juanpujol

I have the same problem. This problem started happening after going from angular#1.2.0-rc.2 to rc3 (and above to current). Here is the error I receive followed by the beef of my directive:

query function not defined for Select2 undefined

.directive('myDirective', function() {
    return {
        restrict: 'E',
        scope: {
            query: '&'
        },
        replace: true,
        template: '<input type="hidden" ng-model="selections" ui-select2="tagOptions" multiple>',
        link: function(scoe, ele, attrs) {
            scope.tagOptions = {
                multiple: true,
                simple_tags: true,
                tokenSeparators: [',', ' '],
                minimumInputLength: 1,
                query: function(query) {
                    var data = // do stuff;
                    query.callback(data);
                }
            }

            scope.$watch('selections', function(newVal, oldVal) {
                // do other stuff
            }
        }
    }
}

Note: I know the query in the isolate scope is not the same query being passed to tagOptions, it's used elsewhere.

cboden avatar Feb 05 '14 15:02 cboden

I was able to resolve this issue by moving some of my code from the link function to the controller function in my directive.

cboden avatar Feb 11 '14 17:02 cboden

cboden -- can you please post an example of our working directive? ... Thank you, Jeff.

jeffpogo avatar Feb 22 '14 00:02 jeffpogo

@jeffpogo All I did was move the scope.tagOptions = lines out of the link function and into the controller: function($scope) function and set tagOptions via $scope.tagOptions =.

cboden avatar Feb 27 '14 17:02 cboden

Thank you @cboden it solved my problem!

CharlesHamel avatar Sep 11 '14 14:09 CharlesHamel