Declares the process of a module and a controller ANGULARJS

Source: Internet
Author: User

For example, the following code. This is a simple application that declares a module and a controller:

Angular.module (' myApp ', [])    . Factory (function() {        return  {             function(msg) {alert (msg);}        }    )    . Controller (' Mycontroller ',function($scope, greeter) {        function() {            Greeter.greet ("hello!" );        };    });

When Angularjs instantiates this module, it looks for greeter and naturally passes the reference to it:

<DivNg-app= "MYAPP">    <DivNg-controller= "Mycontroller">        <ButtonNg-click= "SayHello ()">Hello</Button>    </Div></Div>

Internally, the ANGULARJS process is as follows:
Use the injector to load the application var injector = Angular.injector ([' ng ', ' myApp ']);
Load $controller service via injector: var $controller = injector.get (' $controller ');
var scope = Injector.get (' $rootScope '). $new ();
Load the controller and pass in a scope, as ANGULARJS does at run time var mycontroller = $controller (' Mycontroller ', {$scope: scope})
The above code does not describe how to find greeter, but it does work properly because $injector will be responsible for finding and loading it for us.

Declares the process of a module and a controller ANGULARJS

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.