You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
NgModel needs a way to manually re-run the formatter chain #3407
Say you have a data transformation directive that requires 'ngModel' and adds to the formatter and parser chains. If the transformation is dependent on some dynamic data other than $modelValue or $viewValue, there's no way to do a watch on that data and re-run the formatter chain.
$scope.$watch(function ngModelWatch() {
var value = ngModelGet($scope);
// if scope model value and ngModel value are out of sync
if (ctrl.$modelValue !== value) {
var formatters = ctrl.$formatters,
idx = formatters.length;
ctrl.$modelValue = value;
while(idx--) {
value = formatters[idx](value);
}
if (ctrl.$viewValue !== value) {
ctrl.$viewValue = value;
ctrl.$render();
}
}
});
Should everything inside the (ctrl.$modelValue !== value) check be a function that's exposed publicly on NgModelController?
Reacted by Sofia Vicedomini, LeonardoGentile, Gabriel Smoljar, Georgii Dolzhykov, Ulysse Prygiel, Levi Barker and Arash
+1 would be really nice to have this. the lack of async formatters and parsers makes working with async data pretty nasty. this would help prevent some of the race conditions introduced by synchronous validation against an async data source.
for reference, i did it very similarly to @jpsimons:
Activity
jpsimons commentedon Jul 31, 2013
Well, I guess one could just copy that block into a directive. It's all public stuff. Would be handy to have a function to do it for you though.
feat(ngModel) Allow running the formatters without a change to the mo…
feat(ngModel) Allow running the formatters without a change to the mo…
feat(ngModel) Allow running the formatters without a change to the mo…
feat(ngModel) Allow running the formatters without a change to the mo…
feat(ngModel) Allow running the formatters without a change to the mo…
feat(ngModel) Allow running the formatters without a change to the mo…
bcherny commentedon May 27, 2015
+1 would be really nice to have this. the lack of async formatters and parsers makes working with async data pretty nasty. this would help prevent some of the race conditions introduced by synchronous validation against an async data source.
for reference, i did it very similarly to @jpsimons:
s-light commentedon Jul 11, 2015
just if someone is searching the code snippet - it has moved:
https://github.com/angular/angular.js/blob/master/src/ng/directive/ngModel.js#L822
feat(ngModel): expose function to run model -> view pipeline
feat(ngModel): expose function to run model -> view pipeline
feat(ngModel): expose function to run model -> view pipeline
feat(ngModel): expose $processModelValue to run model -> view pipeline
feat(ngModel): expose $processModelValue to run model -> view pipeline
feat(ngModel): expose $processModelValue to run model -> view pipeline
feat(ngModel): expose $processModelValue to run model -> view pipeline
feat(ngModel): expose $processModelValue to run model -> view pipeline
feat(ngModel): expose $processModelValue to run model -> view pipeline
feat(ngModel.NgModelController): expose $processModelValue to run mod…