ngModel.$render is not called when model change

ε祈祈猫儿з 提交于 2019-12-05 20:17:40

As far as I can see, the $render function is only called once. If you need to update your view on model changes you can add a function to the $viewChangeListeners Array:

ngModel.$viewChangeListeners.push(function () {
    updateView(ngModel.$viewValue);
});

I hope someone could give some more details why $render behaves different in Angular 1.2.

Paul B. Hartzog

This answer shows code you need in your directive to make render fire off when necessary:

TinyMCE <textarea> two way bound with AngularJS

        // When your model changes from the outside, use ngModel.$render to update the value in the textarea
        ngModel.$render = function () {
            textarea.val(ngModel.$viewValue);
        };

Also compare to this render function from angular-ui-tinymce ( https://github.com/angular-ui/ui-tinymce )

    ngModel.$render = function() {
      if (!tinyInstance) {
        tinyInstance = tinymce.get(attrs.id);
      }
      if (tinyInstance) {
        tinyInstance.setContent(ngModel.$viewValue || '');
      }

Plnkr: http://plnkr.co/edit/04AFkp?p=preview

However depending on the timing of the loading of your DOM you may need to set the priority on your directive upwards. :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!