我有来自服务器的小JSON数据,想要在html文件中显示。不幸的是没有工作。任何的想法? 我花了几个小时来找到这些。但仍未找到...... :( 感谢您的反馈。
JS文件:
(function() {
var app = angular.module('myreddit', ['ionic']);
app.controller('RedditCtrl', function($scope, $http) {
$scope.conditions = [];
$http.get('http://50wave.com/deesh.json')
.success(function(response) {
angular.forEach(response.ht, function(child) {
$scope.stories.push(child);
});
});
});
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
});
}());
html文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="myreddit" ng-controller="RedditCtrl">
<ion-pane>
<ion-header-bar class="bar-positive">
<h1 class="title">FootBall</h1>
</ion-header-bar>
<ion-content>
<div class="list">
<div ng-repeat="condition in conditions">
{{conditions.name}}
</div>
</ion-content>
</ion-pane>
</body>
</html>
感谢您的反馈。
答案 0 :(得分:0)
您的应用程序可能存在更多问题,但您没有提供足够的数据进行故障排除,但是从您发布的代码中我至少看到了这两个:
1您正在推送stories
数组,这似乎在您的应用程序中无法读取。我认为应该是:
$http.get('http://50wave.com/deesh.json')
.success(function(response) {
angular.forEach(response.ht, function(child) {
$scope.conditions.push(child);
});
});
2在ng-repeat循环内,你应该对项目而不是集合进行处理,所以不是{{conditions.name}}
而是{{condition.name}}
,所以代码应该是:
<div ng-repeat="condition in conditions">
{{condition.name}}
</div>