I would like to create an editor using some angular directive. From what I can gather from the comment plugin, an editor follows the following footprint. init, prepare, getValue, setValue, focus, open, and close.
The init phase seems to be where I should $compile my template to get a dom object which I need to attach to this instance
Almost like the compile phase of an angular directive
this.instance.rootElement.appendChild (dom);
The prepare phase seems to be the link phase.
The open phase seems to be the place where I need to compute the style coordinate of my editor
And finally the focus phase where I need to set the focus to an element of my editor
Am i right?
Do you have an example of an editor using an angular directive and/or an ng-model
I made some progresses. Right now I need to know how to request the editor to close while saving. I found that I could call cancelChanges() to rollback my changes and close the editor but I am having difficulties save. saveValue seems to want an array of array. If I call close() directly then changes are not saved.
Also need to know when the editor is destroyed to clear my scope.
Responding to my own question if that can help someone.
To accept a change and close the editor, I call finishEditing();
To destroy the created scope during the init phase, I listen to DOM remove events, and destroy my scope
var scope = $rootScope.$new(true);
var content = angular.element ($compile(template) (scope));
content.on ('remove', function () {
scope.$destroy();
});
I am now able to use angular 2-way binding and complex templating in my editor.
Finally make sure that in setValue to set your scope value inside a $apply, otherwise the editor will take up to 2s to update its content.
self.prototype.setValue = function (value) {
content.scope().$apply (function () {
content.scope()['mymodel'] = value; // or whatever you need to do to deserialize your value to your model
});
});
I can see that you are very into the case and made some progress in last few hours. Maybe after this four hours you made even bigger progress from the last given reply. I really want to help you with this case but I would need to see a demo code or get the precise question how to help.
Thanks. I got it working nicely. I can now create editors using template that are angular aware (2 way binding, ng- event aware, with isolated scope). This should help me write custom editor a lot faster. Here is the final code: