Web browsers are sometimes picky about what values they consider valid for attributes. ng-attr
is for binding arbitrary attributes
, select
does not "know" that ng-attr-multiple
is trying to set the multiple
attribute, it just reacts on multiple directly.
Instead I would suggest you to write a wrapper directive which will add the multiple
attribute to your element.
For more information on this see this documentation link:
https://docs.angularjs.org/guide/interpolation
Issue link:
https://github.com/angular/angular.js/issues/13570
var mymodule = angular.module('myApp', []);
function sampleController($scope, $timeout) {
$scope.addAttribute = true;
}
mymodule.controller('sampleController', sampleController)
.directive('multipleAttr', function() {
return {
'restrict': 'A',
'compile': function() {
return {
'pre': function($s, $el, attrs) {
if (attrs.multipleAttr === 'true' || attrs.multipleAttr === true) {
$el.attr('multiple', true);
}
}
}
}
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="sampleController">
<select multiple-attr="{{addAttribute}}">
<option>Hi</option>
<option>Hello</option>
<option>Hey</option>
</select>
</div>
</div>