Getting data from Json


#1

Thanks in advance.
I am really trying to get data from my json file while the user parsing on the button but it doesn’t work… any help?
New with Ionic
Thanks

my ts

 private tips: any[];
  getData() {
    let localData = this.http.get('/assets/advices.json').map(res => res.json());
    localData.subscribe(data =>{
    this.tips=data;

    })

my html

<button ion-fab (click)="getData()">
    <ion-icon name="search"></ion-icon>
</button>
</ion-content>

including the right providers


#2

try to use console.log(res) to see the data that you are gtting


#3

While “it doesn’t work” may make perfect sense to you, it is pretty useless to a stranger. Describe expected behavior, actual behavior, and the difference between the two. Include any relevant error messages (as text).


#4

Sorry, you’re right. I meant that nothing is showing to the user

Like in the png, I see the data of the JSON throw the log but I want the user get the massage of “tip 3” and so on… thanks!


#5

Don’t abuse any here. Define an interface and use it. More importantly, always initialize every object property at the point of declaration, even if it is only to something like [] for arrays or {} for objects. Presumably you have an ngFor somewhere in code you haven’t posted that is throwing errors when attempting to loop across undefined.


#6

Ok.After, how to print the value while pressing ?


#7

i don’t konw how do you wanna display the value of tip so
you can see this tutorial i think gonna help you