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

Commit

Permalink
feat(ngModel): expose $format function
Browse files Browse the repository at this point in the history
  • Loading branch information
Narretz committed Sep 25, 2017
1 parent 77e2466 commit 8978dd7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,26 +880,34 @@ NgModelController.prototype = {
this.$options = this.$options.createChild(options);
},

$setModelValue: function(modelValue) {
this.$modelValue = this.$$rawModelValue = modelValue;
this.$$parserValid = undefined;

$format: function() {
var formatters = this.$formatters,
idx = formatters.length;

var viewValue = modelValue;
var viewValue = this.$modelValue;
while (idx--) {
viewValue = formatters[idx](viewValue);
}

if (this.$viewValue !== viewValue) {
this.$$updateEmptyClasses(viewValue);
this.$viewValue = this.$$lastCommittedViewValue = viewValue;
this.$render();
this.$viewValue = this.$lastCommittedViewValue = viewValue;
}

return viewValue;
},

$setModelValue: function(modelValue) {
this.$modelValue = this.$$rawModelValue = modelValue;
this.$$parserValid = undefined;

if (this.$viewValue !== this.$format()) {
this.$render();
// It is possible that model and view value have been updated during render
this.$$runValidators(this.$modelValue, this.$viewValue, noop);
}
}

};

function setupModelWatcher(ctrl) {
Expand Down

0 comments on commit 8978dd7

Please sign in to comment.