AngularJS how to force an input to be re-rendered on blur

前端 未结 5 1633
攒了一身酷
攒了一身酷 2020-12-24 14:17

I have some custom validation code, which includes a $formatter. (I store currency in pence for correctness, but display in pounds.pence.)

If the user types \'10\'

5条回答
  •  半阙折子戏
    2020-12-24 14:58

    Your controller's $modelValue is being updated properly, however, but since the blur event is happening outside of angular, it seems your $viewValue is not. How about this?

     elm.bind('blur', function() {
           ctrl.$viewValue = (ctrl.$modelValue / 100).toFixed(2);
           ctrl.$render();
     });
    

提交回复
热议问题