I am rendering a list of TinyMCE wysiwygs using ng-repeat directive:
<div ng-repeat="widget in wigdets">
<textarea wysiwyg></textarea> <!-- This is a directive to initialize TinyMCE -->
</div>When i change the order of widgets in controller, TinyMCE's instances are automatically rearranged accordingly.
The problem is that TinyMCE widget is an iframe and iframe state gets reset when it is moved in DOM.
So i need to somehow save TinyMCE contents and remove TinyMCE from element before it is moved, and then init TinyMCE once again and apply saved contents after the movement is finished.
Is there a simple way to somehow hook into ng-repeat and to register callbacks for element movement?
If I have to write my own ng-repeat-custom directive, what is the proper architecture to organize event dispatching between nested scopes in angular way?
How can my wysiwyg directive subscribe to the events from parent scopes if it cannot tell in advance whether it will be inside ng-repeat-custom or used on it's own?
Ivan,
So the ‘reshuffeling’ is under control of your code. Then it’s easy enough. In your code, do a $scope.$emit('widgetsAreShuffled')
In your directive link function something like:
scope.$on('widgetsAreShuffled', function () {
// re-init your tiny-MCE
});
if you need a start and stop event, that’s a bit more work, and you need to make sure that there is a digest cycle after your start event, but before you actually do anything.
Hope this helps a bit?
Regards
Sander
Hi Ivan,
hmm, not sure about it, just test it. If it does not work like you expected, put iy inside a timeout, liek this:
$timeout(function () {
scope.$emit('widgetsAreShuffled');
},0);
that will put it in the NEXT digest cycle, probably the dom is done by then ;)
Regards
Sander