diff --git a/lib/directive/ng_model.dart b/lib/directive/ng_model.dart
index 1b6797ab6..239b2e68b 100644
--- a/lib/directive/ng_model.dart
+++ b/lib/directive/ng_model.dart
@@ -28,6 +28,10 @@ class NgModel extends NgControl implements NgAttachAware {
_exp = 'ng-model=${attrs["ng-model"]}';
}
+ process(value) {
+ render(value);
+ validate();
+ }
attach() {
watchCollection = false;
@@ -51,9 +55,9 @@ class NgModel extends NgControl implements NgAttachAware {
_watchCollection = value;
_removeWatch();
if (_watchCollection) {
- _removeWatch = _scope.$watchCollection((s) => getter(), (value) => render(value), _exp);
+ _removeWatch = _scope.$watchCollection((s) => getter(), (value) => process(value), _exp);
} else {
- _removeWatch = _scope.$watch((s) => getter(), (value) => render(value), _exp);
+ _removeWatch = _scope.$watch((s) => getter(), (value) => process(value), _exp);
}
}
diff --git a/test/directive/ng_model_spec.dart b/test/directive/ng_model_spec.dart
index 41373c351..9240ad1c1 100644
--- a/test/directive/ng_model_spec.dart
+++ b/test/directive/ng_model_spec.dart
@@ -758,6 +758,41 @@ describe('ng-model', () {
}));
});
+ describe('validation', () {
+ it('should happen automatically when the scope changes', inject((Scope scope) {
+ _.compile('');
+ _.rootScope.$digest();
+
+ Probe probe = _.rootScope.i;
+ var model = probe.directive(NgModel);
+
+ expect(model.invalid).toBe(true);
+ expect(model.valid).toBe(false);
+
+ _.rootScope.$apply('model = "viljami"');
+
+ expect(model.invalid).toBe(false);
+ expect(model.valid).toBe(true);
+ }));
+
+ it('should happen automatically upon user input via the onInput event', inject(() {
+ _.compile('');
+
+ Probe probe = _.rootScope.i;
+ var model = probe.directive(NgModel);
+ InputElement inputElement = model.element;
+
+ expect(model.invalid).toBe(true);
+ expect(model.valid).toBe(false);
+
+ inputElement.value = 'some value';
+ _.triggerEvent(inputElement, 'input');
+
+ expect(model.invalid).toBe(false);
+ expect(model.valid).toBe(true);
+ }));
+ });
+
describe('valid / invalid', () {
it('should add and remove the correct flags when set to valid and to invalid', inject((Scope scope) {
_.compile('');