编辑:改变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
我不知道你不会用分号结尾嵌套/内部数组,谢谢。如果我不用我的手机,我可以使用调试器 –