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

Commit 16021b5

Browse files
devversionThomasBurleson
authored andcommitted
fix(input): add support for ng-value
* When a developer uses `ng-value` on the input directive, the directive will just set the attribute on value change, without triggering any `input` event. This means, that we have to watch the value attribute, when the `ngValue` attribute is specified. Fixes #8670 Closes #8742
1 parent 0fad106 commit 16021b5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/components/input/input.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture)
342342

343343
scope.$watch(isErrorGetter, containerCtrl.setInvalid);
344344

345+
// When the developer uses the ngValue directive for the input, we have to observe the attribute, because
346+
// Angular's ngValue directive is just setting the `value` attribute.
347+
if (attr.ngValue) {
348+
attr.$observe('value', inputCheckValue);
349+
}
350+
345351
ngModelCtrl.$parsers.push(ngModelPipelineCheckValue);
346352
ngModelCtrl.$formatters.push(ngModelPipelineCheckValue);
347353

src/components/input/input.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ describe('md-input-container directive', function() {
185185
expect(el).not.toHaveClass('md-input-has-value');
186186
});
187187

188+
it('should set has-value class on container with ng-value', function() {
189+
var el = setup('ng-value="value"');
190+
191+
pageScope.$apply('value = "My Value"');
192+
193+
expect(el).toHaveClass('md-input-has-value');
194+
195+
pageScope.$apply('value = ""');
196+
197+
expect(el).not.toHaveClass('md-input-has-value');
198+
});
199+
188200
it('should set has-value class on container for ng-model input', function() {
189201
pageScope.value = 'test';
190202
var el = setup('ng-model="value"');

0 commit comments

Comments
 (0)