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

ui-select2 and directives

Open mithun-daa opened this issue 11 years ago • 4 comments

Is there anything I need to consider while wrapping ui-select2 inside a custom directive? I am trying to set the select2Options in the link function but those settings never get picked up. Is there anything i am missing?

link: function(scope, elem, attrs) {
                    scope.select2Options = {
                        'placeholder': 'myplaceholder'
                    };
                }

and my html looks like this:

<select style="width:100%;" ui-select2="select2Options" multiple ng-model="select2">

mithun-daa avatar Mar 10 '14 16:03 mithun-daa

Because when uiselect2 is being linked there is no select2Options in the scope. Check this http://stackoverflow.com/questions/17353189/how-can-i-pass-option-changes-to-angular-ui-ui-select2

syabro avatar Mar 11 '14 15:03 syabro

Also here http://stackoverflow.com/questions/17353189/how-can-i-pass-option-changes-to-angular-ui-ui-select2

syabro avatar Mar 11 '14 15:03 syabro

If you associate the options with the scope in a directive controller instead of link it picks up the settings (at least that worked for me):

controller: function($scope, $element, $attrs) {
  $scope.select2Options = {
    'placeholder': 'myplaceholder'
  };
}

That way, if the options don't change later on, there is no need to watch them.

stempler avatar Aug 06 '14 12:08 stempler

Wrap ui-select2 inside a custom directive is not work.

It can be work like this:

... ...

app.controller('CountryController', ['$scope', function ($scope) {
$scope.getCountry = { ... };
} ]);

Alsmile avatar Apr 15 '15 08:04 Alsmile