I'm new in Angular Ionic framework and I'm also currently working on inputting some numbers in the input bar. How to include JSON data to my Angular Ionic page, so that only JSON Data can be inputted? I already see my JSON data on my console.
Here is my sample JSON data
{
"Number": "381238",
"Status": "In Progress",
}
Here is my html code for input bar
<div class="ion-padding basic">
Enter Tracking Number
<div><input type="text" name="track"></div>
</div>
So basically if it enters a number that is from my JSON data it must proceed to the next page and it will show as "In progress" (which is also from JSON data)
Here's the code for data.service.ts which is for loading local/remote JSON data
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
private status: any[];
constructor(private http: HttpClient){}
getLocalData(){
return this.http.get("assets/data/data.json");
}
getRemoteData(){
return this.http.get("");
}
public getStatusFor(trackingNumber: string): string {
return this.status.filter(state => state.Number === trackingNumber).status;
}
}
Here's for home.page.ts
import { Component } from '@angular/core';
import { DataService } from '../services/data.service';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
providers: [DataService]
})
export class HomePage {
status;
constructor(private dataService: DataService) {}
ngOnInit() {
this.dataService.getLocalData().subscribe(data => {
console.log("Local Data:");
console.log(data);
this.status = data;
});
}
}