Code Monkey home page Code Monkey logo

Comments (3)

KillerCodeMonkey avatar KillerCodeMonkey commented on August 17, 2024

just checkout my demo: https://killercodemonkey.github.io/ng-quill/demo.html search for readonly it is working quite well there.

from ng-quill.

rumartcer avatar rumartcer commented on August 17, 2024

Yes, in your example everything works. But in my plunker value of read-only attribure is set to true in $watch function (right after $init, but before quill initialization: you can open console and make sure of it). This is another case when readonly does not work. After some research I found out that problem is in this code in $onChanges hook:

if (editor && changes.readOnly) {
  editor.enable(!changes.readOnly.currentValue)
}

The code in plunker is executed in the following sequence:

  1. $onInit hook of my component is called, vm.readOnly is set to its initial value (false);
  2. $onChanges hook of ng-quill is called, and does almost nothing, because quill has not been initialized and editor variable is undefined;
  3. $onInit hook of ng-quill is called, and sets readonly field in config variable to false;
  4. $postLink hook of ng-quill is called, and schedules _initEditor function calling;
  5. $watch function of my component is called and sets vm.readOnly to true;
  6. $onChanges hook of ng-quill is called, and does nothing once more, because quill is still not initialized. But it had to set readOnly field in config variable because of changes in (5)
  7. _initEditor function of ng-quill is called, and quill is initialized with wrong readOnly value

from ng-quill.

KillerCodeMonkey avatar KillerCodeMonkey commented on August 17, 2024

yep and that is something you should avoid.

just change your code a little bit and use timeout:

$scope.$watch('doesntMatterWhat', function() {
  $timeout(function () {
    vm.readOnly = true;
    console.log('Flag changed!')
   })
})

or just wait for the editor to be created, so use the onEditorCreated callback.

all in all you should avoid watchers ;)

from ng-quill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.