내가 어떻게 내 코드가 이동하기 전에 HTTP 요청을 기다릴 수 주위에 찾고있다, 나는 응답을 HTML로 일부 변수를 채우기 위해 사용하고 있기 때문에 필요한 이유입니다.이오니아 2 기다리는 HTTP 응답
그래서,
질문 1 : 정말 HTTP 요청을하고 약속/관찰 가능한을 반환하는 서비스를 작성해야합니까?
질문 2 : 이것은 내 코드입니다. 응답을 기다리는 코드를 만들려면 여기를 수행 할 수 없습니까?
let link = 'http://working url';
let headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*'
});
let options = new RequestOptions({headers: headers});
this.http
.post(link, this.loginString, options)
.map(res => res.json())
.subscribe(
data => {
let response = JSON.parse(data);
if(response.Successfull){
if(response.ReturnObject.length>0){
this.orders = this.orderJson(response.ReturnObject);
this.ordersWithoutGroup = response.ReturnObject;
this.empty = false;
}else{
this.orders= [];
this.empty= true;
}
}
}, err => {
this.showAlertError();
},() => {
this.loadingPopup.dismiss()
});
}
도움을 위해 미리 감사드립니다.
편집 1 : HTML :
<ion-content class="stable-bg" scroll="true">
<div class="item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<input type="text" placeholder="Search Orders" ng-model="search">
</label>
</div>
<ion-list *ngIf="orders !== null" ng-repeat="(date, group) in orders">
<ion-item class="item-divider">{{ date }}</ion-item>
<ion-item class="item-icon-left item-icon-right" ng-repeat="order in group" (click)="goToDetail(order.ID)">
<div ng-show="order.DocumentNumber.indexOf(search) >-1 || !search ">
<i class="icon ion-card"></i>
<div>Nº {{ order.DocumentNumber }}
<span class="gray pull-right">{{ order.time }}</span>
</div>
<i class="icon ion-ios-arrow-right"></i>
</div>
</ion-item>
</ion-list>
<div ng-show="empty">
<div class="card">
<div class="item item-text-wrap ion-information-circled" (click)="check()">At the moment there isn't any order to
approve.</div>
</div>
</div>
</ion-content>
.TS에 대한
: 내 CONSOLE.LOG 주문에 대한 2
import { Component , OnInit, Injectable} from '@angular/core';
import { NavController, AlertController, LoadingController } from 'ionic-angular';
import { Http, Headers, RequestOptions} from '@angular/http';
import * as moment from 'moment';
@Injectable()
@Component({
selector: 'page-orders',
templateUrl: 'orders.html'
})
export class OrdersPage implements OnInit{
orders: any;
loginString: any;
empty: boolean;
ordersWithoutGroup: any;
loadingPopup: any;;
constructor(public navCtrl: NavController,private alertController: AlertController, private http: Http, private loadingCtrl: LoadingController) {
this.loadingPopup = this.loadingCtrl.create({
content: 'Loading orders...'
});
// Show the popup
this.loadingPopup.present();
this.orders= {}
this.loginString = localStorage.getItem("Auth");
}
ngOnInit() {
this.getOrders();
}
편집
는 UI를하지 창틀 자동 로딩 ... –
편집 질문 모두' .html'과'.ts' 코드가 있습니다. 이것이 작동하지 않을 이유가 없어야합니다. –
지연되어 죄송합니다. 이미 업데이트되었습니다. –