TinyMCE + AngularJS - Keyup event triggered before update of ng-model

379 Views Asked by At

I am fairly new to AngularJS and the TinyMCE editor. I was fiddling around with the keyup event available in TinyMCE when I came across this issue. In the keyup handler, I am accessing one of the controller's ng-model. Here's where things start to get odd. I printed out the ng-model value and the editor's content for comparison purposes and it would seem that the ng-model is lagging by 1 key/character behind i.e. the editor's content is the most up to date. I have a hunch that the model is updated only after the keyup event is finished. That would explain why I am seeing two values here. Perhaps I am going about this the wrong way? Speaking of which, what would be the best/correct way to access the editor's contents? Through angular or TinyMCE?

If it helps, the code looks something like this (They are placed under a single controller):-

        ...
        this.text = "";
        var viewModel = this;
        this.tinymceOptions = {
              setup: function (editor) {
                editor.on('keyup', function (e) {
                  console.log(editor.getContent());
                  console.log(viewModel.text);
                });
              },
              ...
       };

Has anyone encountered this problem before?

Thanks for the help in advance!

0

There are 0 best solutions below