Trying to create a simple directive that shows a textbox or dropdown depending on whether an array is passed for a model
property on the scope.
Anything except explicitly setting false
in the directive markup e.g., multiple="false"
, results in a multi-select dropdown.
Why is this not working? Also, md-select value binding is not working (although textbox binding is working), I suspect for the same reason.
Plunkr available here illustrating the issue
Consumer
<div ng-app='home' layout-padding layout="row">
<content-filter ng-repeat="filter in filters" flex="filter.width" model="filter.model" value="filter.value"></content-filter>
</div>
Consumer Controller
app.controller('MainCtrl', function($scope)
{
$scope.filters =
[
{
model:
{
multiSelect: false,
items:
[
{
label: 'All',
value: 'all'
},
{
label: 'Fail',
value: 'fail'
},
{
label: 'Success',
value: 'success'
}
]
},
value: 'all',
width: '50%'
},
{
value: '123',
width: '50%'
}
];
});
Directive
app.directive('contentFilter', function()
{
return {
restrict: 'E',
replace: false,
template: '\
<md-input-container flex layout="fill" ng-if="model && model.items.length">\
<md-select ng-model="value" multiple="model.multiSelect === true">\
<md-option ng-repeat="item in model.items" ng-value="{{ item.value }}">{{ item.label }}</md-option>\
</md-select>\
</md-input-container>\
<md-input-container flex layout="fill" ng-if="!model">\
<input type="text" aria-label="{{ label }}" ng-model="value" />\
</md-input-container>',
scope:
{
value: '=',
model: '=?'
}
};
});