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

Commit 8978dd7

Browse files
committed
feat(ngModel): expose $format function
1 parent 77e2466 commit 8978dd7

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/ng/directive/ngModel.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -880,26 +880,34 @@ NgModelController.prototype = {
880880
this.$options = this.$options.createChild(options);
881881
},
882882

883-
$setModelValue: function(modelValue) {
884-
this.$modelValue = this.$$rawModelValue = modelValue;
885-
this.$$parserValid = undefined;
886-
883+
$format: function() {
887884
var formatters = this.$formatters,
888885
idx = formatters.length;
889886

890-
var viewValue = modelValue;
887+
var viewValue = this.$modelValue;
891888
while (idx--) {
892889
viewValue = formatters[idx](viewValue);
893890
}
891+
894892
if (this.$viewValue !== viewValue) {
895893
this.$$updateEmptyClasses(viewValue);
896-
this.$viewValue = this.$$lastCommittedViewValue = viewValue;
897-
this.$render();
894+
this.$viewValue = this.$lastCommittedViewValue = viewValue;
895+
}
898896

897+
return viewValue;
898+
},
899+
900+
$setModelValue: function(modelValue) {
901+
this.$modelValue = this.$$rawModelValue = modelValue;
902+
this.$$parserValid = undefined;
903+
904+
if (this.$viewValue !== this.$format()) {
905+
this.$render();
899906
// It is possible that model and view value have been updated during render
900907
this.$$runValidators(this.$modelValue, this.$viewValue, noop);
901908
}
902909
}
910+
903911
};
904912

905913
function setupModelWatcher(ctrl) {

0 commit comments

Comments
 (0)