目前还没有直接的API调用内部格式化链。 这里有一个github feature request。作为变通,你只可以复制的内部代码:
function runFormatters(ctrl){
// this function is a copy of the internal formatter running code.
// https://github.com/angular/angular.js/issues/3407#issue-17469647
var modelValue = ctrl.$modelValue;
var formatters = ctrl.$formatters;
var idx = formatters.length;
var viewValue = modelValue;
while (idx--) {
viewValue = formatters[idx](viewValue);
}
if (ctrl.$viewValue !== viewValue) {
ctrl.$viewValue = ctrl.$$lastCommittedViewValue = viewValue;
ctrl.$render();
ctrl.$$runValidators(modelValue, viewValue, angular.noop);
}
}
this Plunker演示相结合的用法进行额外的参数表:
// deepwatch all listed attributes
scope.$watch(
function(){
return [scope.extraThingToWatchFor, scope.someOther];
},
function() {
console.log("\t runformatters()");
runFormatters();
},
true
);
this is a second Plunker证明上ngModel
// deepwatch ngModel
scope.$watch(
function(){
return ngModelCtrl.$modelValue;
},
function(newData) {
runFormatters(ngModelCtrl);
},
true
);
的deepwatch
这太神奇了! – Sabyasachi