2016-01-16 45 views
-1

我现在正在练习AngularJS。我的问题是:ng-repeat不重复我的数组。AngularJS ng-repeat不会呈现

的index.html:

<!DOCTYPE html> 
<html ng-app="store"> 
    <head> 
    <link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/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 type="text/javascript" src="node_modules/angular/angular.min.js"></script> 
    <script type="text/javascript" src="app.js"></script> 
    </body> 
</html> 


app.js:

(function(){ 
    var app = angular.module('store', []); 
    var gems = [{name: 'Dodecahedron', 
     price: 2.95, 
     description: 'Hidden mass', 
     canPurchase : true, 
     soldOut : true}, 
     {name: 'Pentagonal gem', 
     price: 5.95, 
     description: 'Vacuum mass', 
     canPurchase : false, 
     soldOut : false} 
      }]; 
    app.controller('StoreController', function(){ 
    this.products = gems; 
    }); 
})(); 

任何人能告诉我哪里有故障?

+0

其诺斯与angularJS有关。你有错误的JSON格式..问题是什么。 –

回答

3

您提供额外的}

这里

{name: 'Pentagonal gem', 
    price: 5.95, 
    description: 'Vacuum mass', 
    canPurchase : false, 
    soldOut : false} <- here 
     }]; 

删除

{ 
    name: 'Pentagonal gem', 
    price: 5.95, 
    description: 'Vacuum mass', 
    canPurchase: false, 
    soldOut: false 

}]; 

DEMO

+0

谢谢Anik! :] – Sarit

+0

我想在昨天完成时点击接受,但我必须等待一定的时间后才能接受您的回答。对不起,迟到接受。 – Sarit