【发布时间】:2018-09-21 02:46:26
【问题描述】:
我正在尝试使用 $http.get(...) 从 JSON 文件中获取数据以显示在我的 AngularJS 应用程序中。当我使用 JSON.stringify 运行警报时,警报显示“未定义”。这是我的代码:
JS
var pplApp = angular.module('pplApp', [ 'ngAnimate', 'ngSanitize', 'utilServices' ]);
pplApp.controller('pplCtrl', function($scope, $http) {
$http.get('people.json').then(function(data) {
alert(JSON.stringify(data.People));
$scope.peoples = data.People;
});
});
JSON
{
"People": [
{
"name": "Andrew Amernante",
"rating": 3,
"img": "http://www.fillmurray.com/200/200",
"Description": "Glutenfree cray cardigan vegan. Lumbersexual pork belly blog, fanny pack put a bird on it selvage",
"Likes": [
"Dogs",
"Long walks on the beach",
"Chopin",
"Tacos"
],
"Dislikes": [
"Birds",
"Red things",
"Danish food",
"Dead Batteries"
]
}
]
}
我错过了什么?
更新:这是我在Plunker 中的应用程序
【问题讨论】: