Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

ngOptions does not populate options through selectCtrl #8761

Closed
Delagen opened this issue Aug 25, 2014 · 5 comments
Closed

ngOptions does not populate options through selectCtrl #8761

Delagen opened this issue Aug 25, 2014 · 5 comments

Comments

@Delagen
Copy link

Delagen commented Aug 25, 2014

When i use ng-repeat I can check existense of ngModel value in selected items through selectCtrl.hasOption(value)
When i use ng-options this method is unusable because optionsMap is not populated.

@caitp
Copy link
Contributor

caitp commented Aug 25, 2014

Hi, what you're describing sounds like an issue in your own code rather than angular, since angular doesn't provide a "selectCtrl", and doesn't have anything to do with populating an optionsMap.

Please provide a reproduction (http://jsbin.com, http://plunkr.co) more clearly showing the issue you're having, so that we can determine if there's a bug or not.

@Delagen
Copy link
Author

Delagen commented Aug 25, 2014

http://jsbin.com/buvowimipale/1/edit?html,js,output

Try to change selected value in to select and view the console output

@Delagen
Copy link
Author

Delagen commented Aug 25, 2014

I think selectCtrl must be used in all cases, but it use only in singleMode

      if (optionsExp) setupAsOptions(scope, element, ngModelCtrl);
      else if (multiple) setupAsMultiple(scope, element, ngModelCtrl);
      else setupAsSingle(scope, element, ngModelCtrl, selectCtrl);

Or you can supply any other solution for check if model value is from options list?
Write code in every controller to supply correct value to ngModel is not elegant.

@caitp
Copy link
Contributor

caitp commented Aug 25, 2014

I see what you're saying

@Delagen
Copy link
Author

Delagen commented Aug 26, 2014

When ngModel isn't contains key from options it selects empty option, which may be predefined as:

<select ng-model="..." ng-options="...">
<option value="">empty</option>
</select>

but value in ngModel stay initial and not updated to undefined or something like undefined
So chosen empty option but in ngModel something outside list. So needed method of determine that user choosed option from list.

@caitp caitp added this to the 1.3.0 milestone Sep 3, 2014
@jeffbcross jeffbcross modified the milestones: 1.3.0-rc.4, 1.3.0 Sep 23, 2014
@btford btford self-assigned this Sep 23, 2014
btford added a commit to btford/angular.js that referenced this issue Sep 24, 2014
btford added a commit to btford/angular.js that referenced this issue Sep 26, 2014
@btford btford closed this as completed in 2bcd02d Sep 29, 2014
btford added a commit that referenced this issue Sep 29, 2014
Prior to this fix, options added to a select by ngOptions would not cause
`selectCtrl.hasOption` to return `true`

Closes #8761
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants