gpt4 book ai didi

javascript - 我在 Angular JS 中调用数据抛出 json 但没有收到数据,为什么?

转载 作者:行者123 更新时间:2023-12-03 11:47:27 25 4
gpt4 key购买 nike

我用 json 调用数据,但我的数据没有收到,你可以帮助我吗?

我是 Angular js 新手。

我的代码是这样的

Angular 代码是

var phonecatApp = angular.module('phonecatApp', []);

phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {
$http.get('data.json').success(function(data) {
$scope.phones = data;
});

$scope.orderProp = 'age';
});

HTML 代码为

<!DOCTYPE html>
<html ng-app="phonecatApp">

<head>
<title>Hello i </title>
<link rel="stylesheet" href="style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="script.js"></script>
</head>

<body ng-controller="PhoneListCtrl">
<h1>Hello Plunker!</h1>
<div>Filter By <input type="text" ng-model="query" /> </div>
<div>Order By <select ng-model="orderPop">
<option> Chose One</option>
<option value="name">Name</option>
<option value="price">Price</option>
</select></div>
<ul>
<li ng-repeat="phone in phones | filter:query | orderBy:orderPop ">
{{phone.name}}
<p>{{phone.snippet}}</p>
<h2>Price {{phone.price | currency:"$"}}</h2></h2>
</li>

</ul>
<h4>Total No of Phone {{phones.length}}</h4>
</body>

</html>

<强> Plunker Demo

最佳答案

你错过了 json 中的引号:

    [{
"name": "Nokia X250",
"snippet": "nice application ",
"price": "260"
}, {
"name": "Moto G",
"snippet": "nice oprationg ",
"price": "252"
}]

http://plnkr.co/edit/5N8pndfBNH1EwOnqw5pT?p=preview

关于javascript - 我在 Angular JS 中调用数据抛出 json 但没有收到数据,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25988943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com