Argument ' xxx ' is not a function, got undefined, beginner angular first pit

Source: Internet
Author: User
Tags first string

Finally after the test, in the not updated this period of time, has been busy coping with the exam. But during the period is also exposed to a lot of fun things, such as HTML5 canvas, I used lufylegend HTML5 engine made a "See You have Color" game. And the angular that I've been playing recently.

Angular is also early heard, Ah, has not busy research, taking advantage of holidays, learn a learning. Mu class Network (www.imooc.com) a set of tutorials, or very good. But when it comes to real-time coding, you find it! Examples are not run up, all error, Argument ' xxx ' is not a function, got undefined is the most conspicuous error. Let's take a look at what the "error" code is in the tutorial.

One of the simplest Hello world!

The first introductory tutorials that we generally come into contact with are similar to this, and the code is simple. We have a ng-app as the angular boot port, and then ng-controller= the "Helloctrl" control P tag. View layer, the message value of the data greeting is used in the double curly braces. The following script then defines a Helloctrl function and assigns a value to the $scope.greeting. It all seems so natural to imagine that the browser should appear, "Hello, world!." Unfortunately, the browser has given us such a reply.

  

That's right, that's what the beginning says. So I do not understand why the teacher can run through, but I do not run, we are all Angular-1.3.0. Domestic not to force, difficult to find the answer, finally to StackOverflow found. since Angular-1.3.0 beta15, angular no longer supports global controller! so the question is, how do you define modules in angular?

Of course this blog is to let everyone learn angular time do not encounter cold shoulder, I roughly say a bit. Angularjs, there is a angular.module, the module mechanism is to rely on this to load. Let's see how we can re-emerge the coveted "Hello World".

  

Let's see, what's changed,ng-app= "MYAPP" first assigns a name to the portal, and then initializes the module below. In the Angular.module (string, Modulearray) function, the first string parameter is the name of the module, the second parameter is the module on which it is dependent (which is not needed here), and returns the MyApp module, The Controller method of the module is then used to define the Helloctrl controllers.

Of course we have to explain the dependency module, we can take a look at the third version of the demo which is slightly modified

Simply define a Hellocontroller module so that MyApp can act as a boot port only, without mixing the controller. We can define multiple JS files, clear and clear through the module to comb the structure of the entire project.

Argument ' xxx ' is not a function, got undefined, beginner angular first pit

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.