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

ngOptions required ngModel #7047

Closed
reidreid46 opened this issue Apr 8, 2014 · 8 comments
Closed

ngOptions required ngModel #7047

reidreid46 opened this issue Apr 8, 2014 · 8 comments

Comments

@reidreid46
Copy link

ngModel is required to see any output put into a ngOptions. If ngModel is ommitted, no options are created, and no warning is given.

Possible to?:
a) not require ngModel, display options regardless
b) or show some kind of warning when ngOptions is used without ngModel

@caitp
Copy link
Contributor

caitp commented Apr 8, 2014

Yeah I dunno, I just asked about this. I don't think it would be unreasonable to emit a warning at the very least.

I'm not sure if a patch adding this would be accepted, but it should be pretty trivial to write. Something like

link: function(scope, element, attr, ctrls) {
      // if ngModel is not defined, we don't need to do anything
      if (attr.ngOptions && !ctrls[1]) {
        $log.warn("attempting to use ngOptions directive without ngModel!");
        return;
      }

in the ngOptions directive, should be a good way to inform you, I guess. It's kind of tricky though, maybe.

@caitp
Copy link
Contributor

caitp commented Apr 8, 2014

Brian said it would be worth doing, so maybe we could land a fix for this after all =) Feel free to submit a patch and become a contributor! (caveat: Igor wants to get rid of ng-options, so it might be solved in a different way instead)

@caitp caitp added this to the 1.3.0 milestone Apr 8, 2014
@btford
Copy link
Contributor

btford commented Apr 8, 2014

I actually told @reidreid46 to file this, haha. We ran into this today.

@liorboord
Copy link

@caitp I can see your point and was about to add what you suggested to the code. However, I don't see any use of "log." or "warn" in the entire Angular's Directive's directory code. My guess is that the convention is not to warn about such things. what do you think?

@btford
Copy link
Contributor

btford commented Jul 22, 2014

I think this might belong in our WIP hinting library. /cc @caguillen214 @ealtenho

@btford btford removed the gh: issue label Aug 20, 2014
@petebacondarwin
Copy link
Contributor

Since ngOptions without ngModel does nothing at the moment, it is fundamentally pointless. Therefore I think we should just throw an error if there is an ngOptions without ngModel.

Although this is a breaking change (for 1.5) it shouldn't affect anyone in practice since you get no benefit without it.

Does anyone have a view on that?

@petebacondarwin petebacondarwin modified the milestones: 1.5.x - migration-facilitation, 1.3.x - superluminal-nudge Sep 9, 2015
@Narretz
Copy link
Contributor

Narretz commented Sep 14, 2015

We can simply remove the optional modifier to the ngOptions.require property. It's probably leftover from when ngOptions was an attribute to the select directive.

@Narretz Narretz self-assigned this Sep 14, 2015
Narretz added a commit to Narretz/angular.js that referenced this issue Sep 14, 2015
Closes angular#7047
Closes angular#12840

BREAKING CHANGE:
`ngOptions` will now throw if `ngModel` is not present on the `select`
element. Previously, having no `ngModel` let `ngOptions` silently
fail, which could lead to hard to debug errors. The change should
therefore not affect any applications, as it simply makes the
requirement more strict and alerts the developer explicitly.
@Narretz
Copy link
Contributor

Narretz commented Sep 14, 2015

See #12840

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

No branches or pull requests

6 participants