简体   繁体   English

Angular.js未捕获的错误

[英]Angular.js uncaught error

I'm trying to make a page using angular js and it gives me this error: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.6.3/ $injector/modulerr?p0=store&p1=Error%3A%2…F%2FC%3A%2FUsers%2Fhp%2FDesktop%2FAngular%2Fjs%2Fangular.min.js%3A22%3A179) 我正在尝试使用angular js制作页面,但它给了我这个错误:未捕获的错误:[$ injector:modulerr] http://errors.angularjs.org/1.6.3/ $ injector / modulerr?p0 = store&p1 =错误%3A%2…F%2FC%3A%2FUsers%2Fhp%2FDesktop%2FAngular%2Fjs%2Fangular.min.js%3A22%3A179)

here is my code: 这是我的代码:

 (function () { var app = angular.module('store', ['ngRoute']); app.controller('StoreController', function () { this.products = gems; }); var gems = [ { name: 'Dodecahedron', price: 2.95, description: 'Some gems have hidden qualities beyond their luster, beyond their shine... Dodeca is one of those gems.', canPurchase: true, soldOut: true, }, { name: 'Pentagonal Gem', price: 5.95, description: 'Some gems have hidden qualities beyond their luster, beyond their shine... Dodeca is one of those gems.', canPurchase: true, soldOut: true, }, ]; }); 
 <!DOCTYPE html> <html ng-app="store"> <head> <link rel="stylesheet" href="css/bootstrap.min.css"> </head> <body ng-controller="StoreController as store"> <div ng-repeat="product in store.products"> <h1>{{product.name}}</h1> <h2>${{product.price}}</h2> <p>{{product.description}}</p> <button ng-show="product.canPurchase">Add to cart</button> </div> <script src="js/angular.min.js"></script> <script src="js/app.js"></script> </body> </html> 

You are not invoking your immediately invoked function, it should be: 您没有在调用立即调用的函数,它应该是:

(function () {

   //your code as it is...

})();

(note the () at the very end). (请注意最后的() )。

As a side note, you don't need to inject ngRoute . 附带说明,您无需注入ngRoute

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM