編輯:改變NG-控制器NG-應用在body標籤,是錯字無法通過陣列和後得到angular.js循環到html
我新的角度和我嘗試使用ng-repeat將products[]
中的所有項目發佈到html,但{{expressions}}
作爲文本而不是計算出來。
我沒有我的筆記本電腦,所以我從我的手機上對jsfiddle和w3school的編輯器進行了測試。也許是編輯?有時他們看起來不一致。我下面就CodeAcademy和w3school的教程「塑造角」和我不能告訴我在做什麼錯了,這裏是代碼:
<!DOCTYPE html>
<html>
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body ng-app="myStore">
<div ng-controller="StoreController as store">
<div ng-repeat="x in store.products">
<h1>{{x.name}}</h1>
<h2>${{x.price}}</h2>
<p>{{x.description}}</p>
</div>
</div>
<script>
var app = angular.module('myStore', []);
app.controller('StoreController', function(){
this.products = [
{
name: 'keyboard',
price: 20.47,
description: "well made from scratch",
reviews: [
{
stars: 5,
body: "great fantadtic worksmanship",
author: "[email protected]"
},
{
stars: 4,
body: "amazing sale for the best",
author: "[email protected]"
}
];
},
{
name: "bed",
price: 250.69,
description: "sturdy contriction from panama",
reviews: [
{
stars: 2,
body: "could be better",
author: "[email protected]"
},
{
stars: 1,
body: "shitty",
author: "[email protected]"
}
];
} ];
});
</script>
</body>
</html>
打我吧:) – tavnab
我不知道你不會用分號結尾嵌套/內部數組,謝謝。如果我不用我的手機,我可以使用調試器 –