Angular JS图像数组编码麻烦
Angular JS image array coding trouble
我无法显示图像,它应该显示每个"gem"的缩略图和完整图像,angular教程不够详细…
这是我的HTML代码:<!DOCTYPE html>
<html ng-app="store">
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"/>
</head>
<body ng-controller="StoreController as store">
<ul class="list-group">
<li class="list-group-item" ng-repeat="product in store.products">
<h3>
{{product.name}}
<em class="pull-right">{{product.price | currency}}</em>
<img ng-src="{{product.images[0].full}}"/>
</h3>
</li>
</ul>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
JS代码:
(function(){
var app = angular.module('store', []);
app.controller('StoreController', function(){
this.products = gems;
});
var gems = [
{
name: "dodecahedron",
price: 2.95,
description: ". . .",
images: [
{
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
},
{
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
},
],
name: "Pentagonal Gem",
price: 5.95,
description: ". . .",
images: [
{
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
},
],
]
})();
我怎样才能使它工作?
它应该是像一个商店,但我似乎不能让JS(或html)工作正常,而不是我只是得到"{{product.name}} {{product.price | currency}}"
在浏览器当我运行文档
您的var gems = [
变量格式不正确。
我已经修复了var gems
变量,你的代码工作得很好。右花括号[
、{
位置不对
检查下面没有图片的片段:
(function(){
var app = angular.module('store', []);
var gems = [{
name: "dodecahedron",
price: 2.95,
description: ". . .",
images: [
{
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
},
{
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
},
]},{
name: "Pentagonal Gem",
price: 5.95,
description: ". . .",
images: [
{
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
},{
full: 'gemfull.gif',
thumb: 'gemthumb.gif'
},
],
}
];
app.controller('StoreController', function(){
this.products = gems;
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="store">
<head>
</head>
<body ng-controller="StoreController as store">
<ul class="list-group">
<li class="list-group-item" ng-repeat="product in store.products">
<h3>
{{product.name}}
<em class="pull-right">{{product.price | currency}}</em>
<img ng-src="{{product.images[0].full}}"/>
</h3>
</li>
</ul>
</body>
</html>
相关文章:
- 将地理编码结果转换为php变量以发布到mysql数据库
- Json在完整日历中对数据进行了编码
- 如何对每个用户每天只允许单击一次的按钮进行编码
- Javascript字符集编码
- 如何在javascript转换编码中将一个动态值从一个表单添加到另一个页面
- base64编码的图像比intranet中的常规图像好吗
- 我不知道我的编码有什么问题.(JavaScript)
- 为什么字符编码对URL很重要
- 如何在做PHP时在base64中动态编码;preg_ replace”;
- 如何将JSON编码的PHP数组发送到同一页面上的数据表
- 如何使Jquery编码的动态下拉菜单与PHP GET变量协调工作
- JavaScript代码,用于在浏览器中显示字节数组中的PDF文件(非base64编码)
- 以HTML文件中的编码形式脱机存储图像
- 从Base64 Ionic编码和解码图像
- 错误编码的Adsense广告正在扼杀我的网站's的性能
- 如何在JS中编码URL并在PHP中解码
- 麻烦将coffee脚本片段移动到rails中自己的类中
- 在解决来自 coderbyte 的 JavaScript 编码挑战时遇到麻烦
- Angular JS图像数组编码麻烦
- 使用JavaScript解决这个编码难题很麻烦