Skip to content Skip to sidebar Skip to footer

Conditional Multi-select Directive In Angular

I am creating a select box directive where, as part of it, I need to specify if the select is multiple or not. I have tried to set a multiple property in one of my scope objects a

Solution 1:

Create your own directive that use ng-ifs or write a directive with logic to switch between single and multiple. Looks like angular didn't want to do that but if it works for you, go for it.

Solution 2:

One possibility would be to add a link function to your directive definition that checks the properties.multiple value off your scope and then uses jquery or jqLite to set the attribute. So:

angular.directive("yourDirective", function() {    return {
      link: function(scope, element, attrs) {
           if (scope.properties.multiple) {
              elements.children("select").attr("multiple",true);
           }
      },
      templateUrl: "yourtemplate.html", ...    
      } 
});

Post a Comment for "Conditional Multi-select Directive In Angular"