我使用 services.js 中的代码创建了一个带有显示动态列表的选项卡的 ionic 项目:
.factory('Interventions', function($http) {
var interventions = {};
$http({
method: 'POST',
url: 'http://172.20.1.1/list.php'
}).success(function(data, status, headers, config) {
interventions = data;
});
return {
all: function() {
return interventions;
},
get: function(iid) {
return interventions[iid];
}}
})
问题是当我加载页面时,我的应用程序最初没有显示列表,但只有当我刷新它(使用 doRefresh)或当我转到其他选项卡并返回第一个选项卡时。有解决方案吗?
先感谢您
我在 ncontroller.js 中的代码:
.controller('InterventionCtrl', function($scope, $http, Interventions) {
$scope.interventions = Interventions.all();
$scope.doRefresh = function() {
$http.get('http://172.20.1.1/list.php')
.success(function(newItems) {
$scope.interventions = newItems;
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
});
};
})
.controller('InterventionDetailCtrl', function($scope, $stateParams, Interventions) {
$scope.intervention = Interventions.get($stateParams.iid);
});
和我的观点:
<ion-view title="Interventions">
<ion-content>
<ion-list>
<ion-item ng-repeat="intervention in interventions" type="item-text-wrap" href="#/tab/interventions/{{intervention.ID}}">
<h3>{{intervention.Nom}}</h3>
</ion-item>
</ion-list>
</ion-content>
</ion-view>