首页 > 代码库 > angularjs取Sevice和directive的引用
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.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。