ui-select in a modal does not bind to model
Hi, I have a modal with a basic template (nothing else than below) :
<p>Selected serieData.selected: {{serieData.selected}}</p>
<ui-select ng-model="serieData.selected" theme="bootstrap" ng-disabled="disabled">
<ui-select-match placeholder="Select a serie to display">{{$select.selected}}</ui-select-match>
<ui-select-choices repeat="serieData in seriesAvailable">
<div ng-bind-html="serieData.name | highlight: $select.search"></div>
<small ng-bind-html="serieData.description | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
and a controller
.controller('widgetSampleEditCtrl', function ($scope, $modalInstance, widget, Series) {
$scope.widget = widget;
$scope.seriesAvailable = new Array();
Series.getSeries().then(function(series) {
$scope.seriesAvailable = series;
});
});
When i select something in the select directive, the binding does not work and i can't find a way to retrieve the selected value Behind the modal, in the main screen i have another ui-select item and this one works without any issue
+1
@my9074 i solved it by adding a form around the select and bind a new variable with the form name as a prefix
<form class="form" name="form" ng-submit="configureWidget(form)" novalidate>
...
<ui-select ng-model="form.serieSelected" ng-disabled="disabled">
<ui-select-match placeholder="Select a serie to display">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="serieData in seriesAvailable">
<div ng-bind-html="serieData.name | highlight: $select.search"></div>
<small ng-bind-html="serieData.description | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
...
</form>
I did something similar but made the ui-select's variable a $root variable
I've discovered that the solution / issue generally speaking is that binding will only occur if you have a "dotted" object in the ng-Model attribute.
| CODE | Works | Fails |
|---|---|---|
| Controller | scope.x={}; | scope.selections=[]; |
| ui-select attrib | ng-Model="x.selections" | ng-Model="selections" |
| result HTML | {{x.selections}} | {{selections}} |
@ERobishaw thanks a lot!
@ERobishaw you're a life saver! I spent about 4 hours trying to get this to work.