Javid Asgarov
Javid Asgarov

Reputation: 1532

$injector:modulerr - Angular JS

So, I am learning Angular JS from codeschool course "Shaping up with angular js". The guy on the videos says, that wrapping code in (function(){}) is a good habbit.

BUT, when I do that Im getting an error[$injector:modulerr]`. Without this self-called function syntax everything works fine. And it bothers me, why they tell to do this way, and why does it cause error?

Upvotes: 0

Views: 62

Answers (2)

huan feng
huan feng

Reputation: 8623

Usually the format should look like this:

angular.module("gemStore", []).controller("StoreController", function () {
    var gems = [
        { name: "Dodecahedron", price: 2, desc: "some description", canPurchase: true },
        { name: "Pentagonal gem", price: 5.95, desc: "...", canPurchase: true }
    ];
    this.products = gems;
})

Upvotes: 0

Jai
Jai

Reputation: 74738

Seems that you are missing the (); self executing braces at the end of your anonymous function:

(function(){
  // all your code
})();
//^^^--------------add this (); at the closing.

Upvotes: 3

Related Questions