2017-03-19 69 views
-1

我正在尝试使用角度js来创建一个页面,它给了我这个错误:Uncaught Error:[$ 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)Angular.js未被捕获的错误

这里是我的代码:

(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>

+0

你在哪里将控制器绑定到视图?我无法在模板中看到任何ng控制器,也无法看到路由配置。 – Dario

+0

其题外:“为什么我的代码不能运行..” – lin

+0

@Dario我更新了这个问题,但它没有工作,要么它有相同的错误 – stephjhonny

回答

2

你并没有调用你的立即调用的函数,它应该是:

(function() { 

    //your code as it is... 

})(); 

(注意最后的())。

作为便笺,您不需要注入ngRoute

+0

nope,它没有工作 – stephjhonny

+0

奇怪......这个作品http://codepen.io/dariospadoni/pen/pRPLoL – Dario

+0

:')它可能是与npm或不是?或配置错误? – stephjhonny

相关问题