我有这个代码,但是当我尝试运行时,注意到了。 我有一个web服务返回带有一些数据的json,我需要在应用程序上列出它。
我的app.js是:
(function (){
var app = angular.module("opoBUS");
app.controller("StopCtrl", ["$scope", "$http", "$ionicLoading", "DataStore", function ($scope, $http, $ionicLoading, DataStore) {
var self = this;
this.linhas = [];
this.getLinhas = function () {
$ionicLoading.show({
template: 'Loading...'
});
$http.get("http://www.stcp.pt/pt//itinerarium/callservice.php?action=lineslist")
.success(function (data) {
self.linhas = data;
DataStore.linhas = self.linhas;
$ionicLoading.hide();
$scope.$broadcast('scroll.refreshComplete');
})
.error(function (error) {
DataStore.linhas.length = 0;
$ionicLoading.hide();
});
};
this.adicionarFavorito = function(linha){
DataStore.adicionarFavorito(linha);
};
if (DataStore.linhas.length === 0) {
this.getLinhas();
}
}]);
})();
我的paragem.html是:
<ion-view view-title="Paragem">
<ion-content overflow-scroll="true" padding="true">
<ion-refresher pulling-text="Pull to refresh..." on-refresh="StopCtrl.getLinhas()">
</ion-refresher>
<ion-list>
<div class="list card" collection-repeat="linha in StopCtrl.linhas">
<div class="item item-avatar">
<h2>{{linha.code}}</h2>
<p>Description {{linha.description}}</p>
</div>
<div class="item item-body">
<p>
<a href="#" class="subdued">{{linha.pubcode}}</a>
<a href="#" class="subdued">Codigo {{linha.code}}</a>
</p>
</div>
</div>
</ion-list>
</ion-content>
</ion-view>
假设在json中包含所有信息的列表。
答案 0 :(得分:0)
尝试更改
self.linhas = data;
到
self.linhas = data.records
此处有半功能的codepen ... http://codepen.io/aaronksaunders/pen/grGJvw?editors=1010
您的浏览器需要一个CORS插件才能让codepen正常工作