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

feat(ngModel): add $overrideModelOptions support #15415

Merged

Conversation

petebacondarwin
Copy link
Contributor

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

feature

What is the current behavior? (You can also link to an open issue here)

no obvious way to programmatically change model options for an ngModel directive

What is the new behavior (if this is a feature change)?

Adds $overrideModelOptions method

Does this PR introduce a breaking change?

No

Please check if the PR fulfills these requirements

Other information:

@petebacondarwin petebacondarwin added this to the 1.6.x (post 1.6.0) milestone Nov 21, 2016
@petebacondarwin petebacondarwin force-pushed the model-option-override branch 2 times, most recently from caa180a to c4debc4 Compare November 21, 2016 13:30
*
* The previous `ModelOptions` value will not be modified. Instead, the
* new `ModelOptions` object will inherit from the previous value of
* `NgModelController.$options`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this is the only place we publicly document NgModelController.$options. I don't think it is a good idea (especially considering we don't specify what its type is or what the API of this ModelOptions type is).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll fix this

ctrl.$overrideModelOptions({ debounce: 1000, updateOn: 'blur' });
expect(ctrl.$options.getOption('debounce')).toEqual(1000);
expect(ctrl.$options.getOption('updateOn')).toEqual('blur');
expect(ctrl.$options.getOption('updateOnDefault')).toBe(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

it('should inherit from a parent model options', inject(function($compile, $rootScope) {
var element = $compile(
'<form name="form" ng-model-options="{debounce: 1000, updateOn: \'blur\'}">' +
'<input ng-model="value" name="input">' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Inconsistent indentation 😁

'<input ng-model="value" name="input">' +
'</form>')($rootScope);
var ctrl = $rootScope.form.input;
ctrl.$overrideModelOptions({ debounce: 2000, '*': '$inherit' });
Copy link
Member

@gkalpak gkalpak Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Ideally, I would repeat the same test without the '*': '$inherit' part (just in case), but this should not block landing the PR.

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request Nov 22, 2016
This change allows developers to modify the model options for an `ngModel`
directive programmatically.

Closes angular#15415
@petebacondarwin petebacondarwin changed the title feat(ngModel): add support feat(ngModel): add $overrideModelOptions support Nov 23, 2016
@Narretz
Copy link
Contributor

Narretz commented Jan 30, 2017

@petebacondarwin This has been approved and can be merged. I assigned you as the creator.

petebacondarwin added a commit that referenced this pull request Feb 1, 2017
This change allows developers to modify the model options for an `ngModel`
directive programmatically.

Closes #15415
@petebacondarwin petebacondarwin merged commit 2b00e88 into angular:master Feb 1, 2017
ellimist pushed a commit to ellimist/angular.js that referenced this pull request Mar 15, 2017
This change allows developers to modify the model options for an `ngModel`
directive programmatically.

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

Successfully merging this pull request may close these issues.

4 participants