Closed whitehat101 closed 10 years ago
So it's something like a global access to all the instances ?
In my setup, I have a 3-5 CM instances on my page, but each ui-codemirror is in its own directive/scope. Since $broadcast
sends messages down the scopes (towards the leafs), I can $scope.$broadcast
from my directive to only send messages to a single ui-codemirror.
You could also broadcast to every ui-codemirror if you wanted, $rootScope.$broadcast
or if you $broadcast
from a scope that is simply a parent to all the ui-codemirror scopes.
A better example probably would have been codeMirror.refresh()
If you have ui-codemirrors display:none
'd you could broadcast the refresh command to all of them in your fragment. Just one, or many -- however you layered your scopes.
$scope.$broadcast('CodeMirror', function(codeMirror) { codeMirror.refresh() })
OK That a cool feature. I'm adding it !
Hey is this feature officially documented anywhere? Can I depend on the event not being removed in the future?
Currently the only way to interact with the CM instance is to get it through the onLoad callback (often storing it for later use).
I've added an event callback that allows direct and spontaneous access to the CM instance.
CoffeeScript example:
This allowed for much cleaner code in my controllers and link functions.