Angularjs references to sevice and directive

Source: Internet
Author: User

Take sevice and directive references 3:grab any Services

We can grab a reference to any service using the injector function of element where is ngApp defined (or grab the $rootEleme NT manually if using angular ' s bootstrap method):

>Angularelement ( ' html ' ).  Injector ().  Get ( ' MyService ' ) -> object Span class= "p" >{undo: function redo: function_pushaction< Span class= "O" >: functionnewdocument: functioninit: function                /span>                

We can then call methods on this 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 {}

The last one was more advanced and not used as frequently.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.