We can grab a reference to any service using the injector
function of element where ngApp
was defined (or grab the $rootElement manually if using angular‘s bootstrap method):
> angular.element(‘html‘).injector().get(‘MyService‘)
-> Object {undo: function, redo: function, _pushAction: function, newDocument: function, init: function…}
We can then call methods on that service just like we could if we injected it.
Some directives define a controller with certain additional (often shared) functionality. To access the instance of a controller for a given directive from the console, just use the controller()
function:
> angular.element(‘my-pages‘).controller()
-> Constructor {}
This last one is more advanced and not used as frequently.
angularjs取Sevice和directive的引用,布布扣,bubuko.com
原文:http://www.cnblogs.com/yoyogis/p/3820019.html