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

ui-select in a modal does not bind to model

Open pihomeserver opened this issue 11 years ago • 7 comments

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

pihomeserver avatar Nov 09 '15 14:11 pihomeserver

+1

my9074 avatar Nov 16 '15 02:11 my9074

@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>

pihomeserver avatar Nov 16 '15 07:11 pihomeserver

I did something similar but made the ui-select's variable a $root variable

jlandry avatar Nov 19 '15 21:11 jlandry

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 avatar Dec 08 '15 20:12 ERobishaw

@ERobishaw thanks a lot!

sch4lly avatar Dec 21 '15 11:12 sch4lly

@ERobishaw you're a life saver! I spent about 4 hours trying to get this to work.

dwheatfall avatar Feb 29 '16 02:02 dwheatfall

As per FAQ you must bind to object with ngModel.

Closing as not a bug.

user378230 avatar Mar 21 '16 13:03 user378230