Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Model's value is not idempotent #156

@slavafomin

Description

@slavafomin

Hello!

I'm developer of Angular.js Input Modified directive. Our module is used to detect changes in the form fields. We heavily depend on the ngModel interface in our implementation and I wanted to say that you've made a great job of implementing it properly.

However, there's an issue with model value idempotency. Sometimes, when you take current value from the directive and then feed it back to it, you will get yet another value. It looks like TinyMCE is refactoring the HTML code when you feed it to it (reordering attributes for example). Maybe it's not a strict violation of the ngModel interface, but it breaks our model change detection mechanism (because returned value is not always equal to provided one).

For now, I have had to add a stabilization function to our module in order to overcome this problem. I suggest you to implement it in your code as well (for better compatibility).

/**
 * Stabilizes model's value.
 * This is required for directives such as Angular UI TinyMCE.
 */
function stabilizeValue (callback) {
  var initialValue = modelCtrl.$modelValue;
  modelCtrl.$modelValue = null;
  $timeout(function () {
    modelCtrl.$modelValue = initialValue;
    $timeout(callback, 0);
  }, 0);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions