A date format setting is in the scope.
It is used by filters to display dates in label and by a directive putting a function in $formatters from ngModel to format date in input.
When the format setting in the scope changes, the date displayed through the filters is refreshed by angular.
But not the input fields through $formatters.
The only way to force this refreshed we have found is to set all fields to null, then in $timeout to reset them to the value to display to force the reexecution of the $formatters.
Is there a better way to do this?
Answer:
By merging answer from Sergey Moiseev and answer to 11380866, I was able to add a satisfying solution to the directive.
Store the settings in rootscope (as it is used from lot of directive in solated scope) and react to it by the generic code:
$rootScope.$watch('userSettings.dateFormat.fmt', function (newVal, oldVal, scope) {
if (newVal != oldVal) {
var viewValue = ngModelCtrl.$modelValue;
for (var i in ngModelCtrl.$formatters) {
viewValue = ngModelCtrl.$formatters[i](viewValue);
}
ngModelCtrl.$viewValue = viewValue;
ngModelCtrl.$render();
}
});
Thanks!