I am following an tutorial in Ionic 3 about HTTP. I have made a data provider called data.ts. This is my method:
data.ts
getRemoteData() {
return this.http.get(this.statusUrl);
}
I am calling this method in home.ts like this:
home.ts
ionViewDidLoad() {
this.dataService.getRemoteData().subscribe(data => console.log(data));
}
This is my result in my google dev tool from console.log(data)
:
[{"status":"P","plate":"test2","code:"MGP150151","message":"fail"}
,{"status":"P","plate":"test3","code":"MGP160298","message":"fail"}
,{"status":"P","plate":"test4","code":"MGP140085","message":"succes"}
,{"status":"O","plate":"test5","code":"MGP150175","message":"succes"}]
The data provider is working good. Now my problem is I want to select just one object in this array. For example: the user enters test3
based on plate
and the app must return this result:
{"status":"P","plate":"test3","code":"MGP160298","message":"fail"}
Then I am binding like this:
<ul>
<li *ngFor="let jsondata of data>
<span>{{jsondata.plate}}</span>
</li>
</ul>
I have searched over the internet and I found something like this:
https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Array/find
I don't know how to use this on my JSON object array.
Can someone point me in the right direction?
Kind regards
Source I used:
https://www.joshmorony.com/loading-remote-json-data-with-http-in-ionic-2/