Comments (13)
there is already a $timeout if something changed.
View value is also updated.
$timeout(function () {
$scope.modelLength = editor.getLength();
setClass();
ngModel.$setViewValue(editor.getHTML());
}, 0);
it works well in my projects.
Maybe you have a scope issue.
Put you model on a nested object like:
ng-model="data.myModel"
from ng-quill.
Maybe I did something wrong. Here is my code :
<textarea class="form-control" rows="3" ng-model="elt.myHTML"></textarea>
<ng-quill-editor ng-model="elt.myHTML" toolbar="true"></ng-quill-editor>
It's in a directive which displays a form for the elt :
<elt-form elt="crud.data.form"></elt-form>
Anyway, when I edit the textarea, the editor is not updated...
Any idea on where I'm wrong ?
from ng-quill.
Looking closer at your code, it seems that you put the editor value when it's created (with the timeout).
But if you change the value externally, the editor is not updated.
I will try to solve this tomorow :)
from ng-quill.
It is set 1-time in the watcher to set the initial value in the editor (thats why making setHtml)
After that i am listening to the editor.on('text-change')-event. To set correct modelViewValue...
it works in my project really well.
But i only get the value from the controller once (from database) -> after that i change the value in the editor -> send the value to the database.
But my model is a nested object ;).
That was it.
from ng-quill.
Ah okay.. now i see your example.
No it will not work in that way. because in most cases you have the editor and you are changing the model in "one-direction" -> editor changes the model
You are trying to change the value in the editor from another text-input.
Set your default value in your controller on your model.
from ng-quill.
Yes !
It's the way controller -> editor after the first time...
My use case is a crud where I have a list of items and when I click on one, I show the form to edit it. The form view is toggled with ng-show so the editor is not destroyed when I change from selected item.
For now, my workaround is to use ng-if to destroy and recreate the form but it's just a workaround.
I will look to update editor content on model change.
Thanks for your quick responses :)
from ng-quill.
You may try something like that:
After the editor instance is created "$scope.$emit('editorCreated', editor);" triggers.
So you can catch the editor in your controller and if -> your model changes use editor.setText or setHtml to update the editor content.
from ng-quill.
because i do not get any answer in time.. i close the issue. you can reopen if you have any other problems related to this.
from ng-quill.
Hi!
I tried to use the API methods to update programatically the editor content, but when I change the model to a empty string and use editor.setHtml to update the content, I got the error below:
ionic.bundle.js:25642 Error: [$rootScope:inprog] $apply already in progress
http://errors.angularjs.org/1.4.3/$rootScope/inprog?p0=%24apply
at ionic.bundle.js:13380
at beginPhase (ionic.bundle.js:29512)
at Scope.$apply (ionic.bundle.js:29256)
at b.<anonymous> (ng-quill.js:306)
at b.f.emit (quill.min.js:6)
at b.emit (quill.min.js:9)
at a.checkUpdate (quill.min.js:7)
at b.setHTML (quill.min.js:9)
It works, but always get the error in console log.
EDIT
Sorry for my mistake. The below "solution" is wrong.. with timeout, the cursor not works as expected!!
I resolved it problem by wrapping the code (line 306) inside $timeout
:
$timeout(function () {
$scope.$apply(function () {
// Calculate content length
$scope.modelLength = editor.getLength();
// Check if error class should be set
if (oldChange) {
setClass();
}
var setValue;
if (config.save === 'text') {
setValue = editor.getText();
} else if (config.save === 'contents') {
setValue = editor.getContents();
} else {
setValue = editor.getHTML();
}
// Set new model value
if(editor.getLength() <= 1) {
ngModel.$setViewValue('');
} else {
ngModel.$setViewValue(setValue);
}
});
});
Let me know if I am doing something wrong.
Thank you!
from ng-quill.
wrapping $timeout and $scope.$apply should not be done.
Could you show me, how you are using the API to set the value?
from ng-quill.
I have a modal with ngquill.
<div class="editor-wrapper">
<ng-quill-editor data-tap-disabled="true" style="height:400px !important;" class="selectable" ng-model="vm.editorText" toolbar="true" toolbar-entries="size bold list bullet italic underline align color"></ng-quill-editor>
</div>
The first time when page is loaded, everything works well.
Scenario:
- Open the modal;
- Write some text in ngquill;
- Save the doc
But I need add more documents or edit the older one. So I open the modal again.
function openAddModal(id) {
//Clear the model.
//If I set a white space (" ") instead a empty string, I don't need to use the API method (setHtml), because the editor updates!
//I was using this workaround to clear the model and the editor, but I realized that when I paste some text with "Ctrl + V", the model does not update without typing anything.
vm.editorText = "";
//New doc
if(id == null) {
//Clear the editor.
//Here I got the error
editor.setHTML('<div></div>');
vm.modalNewDocument.show();
} else {
//get the document...
vm.editorText = vm.document.content;
vm.modalNewDocument.show();
}
}
from ng-quill.
try to wrap only
editor.setHTML('<div></div>');
in $timeout
from ng-quill.
Thank you!!!
It worked very well! :D
from ng-quill.
Related Issues (20)
- Toolbar at the bottom HOT 2
- Hardcoded quill.js link in snow theme HOT 1
- max-length and min-length attributes does not work properly for non-empty model HOT 1
- read-only flag does not work properly HOT 3
- Quill editor content is not equal to ngModel value after pasting unsupported content into quill HOT 6
- Html Tag Attributs Removed HOT 9
- Version Issue HOT 2
- Font-sizes not working HOT 1
- Locks all the events after one successful redirect. HOT 1
- can not display successfully HOT 2
- rel="noopener noreferrer" on links when text is processed with ng-quill HOT 2
- Set Optional Data via Formly HOT 1
- onEditorCreated not updating HOT 1
- Add BSV as donation address. HOT 1
- Came here to deliver kudos HOT 2
- Global event handler HOT 1
- On-Content-Changed event firing on load HOT 3
- Is there a way to initialize the ng-quill content before it is there in the DOM HOT 1
- Any way to focus quill editor onLoad? HOT 2
- 'ng-quill-toolbar' is not a known element HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-quill.