码迷,mamicode.com
首页 > Web开发 > 详细

angularjs取Sevice和directive的引用

时间:2014-07-02 14:57:17      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:java   javascript   html   cti   for   io   

取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的引用,布布扣,bubuko.com

angularjs取Sevice和directive的引用

标签:java   javascript   html   cti   for   io   

原文地址:http://www.cnblogs.com/yoyogis/p/3820019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!