我正在创建一个电子商务平台,我有一个JSON产品列表,我正在阅读。我希望这个工作的方式是我可以这样做:
{{products.products[parseInt(window.location.search)]}}
我目前的代码:
product.controller('products', ['$http', '$location',
function ($http, $location) {
var store = this;
console.log = $location.search();
this.id = $location.search();
store.products = [];
$http.get('http://adambkeim.com/js/data.json').success(function (data) {
store.products = data;
}).error(function (data, status, headers, config) {
console.log(status);
console.log(data);
});
}
]);
然后在主页面中:
<div class="container">
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron" ng-controller="products as products">
<h1 style="color: green;">{{products.products[products.id].name}}</h1>
<p>{{products.products[0].desc}}</p>
<p>To see the difference between static and fixed top navbars, just scroll.</p>
<p>
<a class="btn btn-lg btn-success" href="/products/products.html?id=0" role="button">Learn More</a>
</p>
</div>
</div>
现在,parseInt或window.location都没有获取任何值,当我尝试打印到控制台时,它无法打印出任何内容。
答案 0 :(得分:0)
我遇到了同样的问题,现在你可以这样做:
Car