angularjs取Sevice和directive的引用

取Sevice和directive的引用

3: Grab any Services

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.

4: Access controller for directive

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的引用,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。