I want to display a message when Data is not found from our API after the user input its number and the button is clicked.
Here is my html
<ion-item>
<ion-input placeholder="Number" [(ngModel)]="myNum"></ion-input>
<ion-button (click)="onClick()">UPDATE</ion-button>
</ion-item>
</ion-list>
<ng-container *ngIf="!error; else errorContent">
<p *ngFor="let order of orders; let i=index;">
<ion-item *ngIf="i==0">Number : <b>{{ order?.Number }}</b></ion-item>
</p>
</ng-container>
<ng-template #errorContent>
<p>
<span style="color: red;">{{error}}</span>
</p>
</ng-template>
<ng-template ngif="blank">
Document Number not Found
</ng-template>
</ion-content>
Here.s my page.ts which is for displaying the Data and for when the button is clicked. I tried to add a property (this.blank) for null, 0 and length = 0 for API.
ionViewWillEnter() {
// Load the data
this.prepareDataRequest().subscribe( //comment this if you will use Api Url
//this.dataService.getRemoteData(this.myNum).subscribe( //comment this if you will use local data
(data:any) => {
// Takes data into in single Array and print
this.actualOrders = data.output.OrderTracking;
this.orders = data.output.OrderTracking;
this.blank = data.output.OrderTracking == null |data.output.OrderTracking === 0 || data.output.OrderTracking.length === 0;
},
err => {
// Set the error information to display in the template
this.error = `An error occurred, the data could not be retrieved: Status: ${err.status}, Message: ${err.statusText}`;
}
);
}
onClick () {
this.dataService.getRemoteData(this.myNum).subscribe( //comment this if you will use local data
(data:any) => {
// Takes data into in single Array and print
this.orders = data.output.Result.OrderTracking;
console.log("Remote Data:");
console.log(data);
this.blank = data.output.OrderTracking == null |data.output.OrderTrackin === 0 || data.output.OrderTracking.length === 0;
},
err => {
// Set the error information to display in the template
this.error = `An error occurred, the data could not be retrieved: Status: ${err.status}, Message: ${err.statusText}`;
}
);
}