Three ways to Angularjs a controller

Source: Internet
Author: User

AngularJS's controller is actually a method, it has three kinds of wording:

The first type:

[JavaScript]View PlainCopy
    1. <pre name="code" class="JavaScript" >var appcontroller = [' $scope ', function ($scope) {
    2. $scope. Notifyserviceonchage = function () {
    3. Console.log ($scope. windowheight);
    4. };
    5. }];
    6. App.controller (' AppController ', AppController);

When defining AppController, first declare the parameters that the method needs to inject, and then define the method body. Finally, bind the AppController to the app.

The second type:

[JavaScript]View PlainCopy
    1. App.controller (' appcontroller ', function ($scope) {
    2. $scope. Notifyserviceonchage = function () {
    3. Console.log ($scope. windowheight);
    4. };
    5. })


Directly in the app's Controller property definition, first the controller name, then the method body.

The third type:

[JavaScript]View PlainCopy
    1. function AppController ($scope) {
    2. $scope. Notifyserviceonchage = function () {
    3. Console.log ($scope. windowheight);
    4. };
    5. }


Write the method directly, and then reference the method in Ng-controller

Excerpt from: http://blog.csdn.net/teddyu_leo/article/details/49816721

Three ways to Angularjs a controller

Related Article

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.