Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Getting data from JSON file

$
0
0

@JobsMonika wrote:

I have file of tips that I want to print. Every pressing on the button the next tip will print from the json file. So I wrote a function, but right to now the reading from the file doesn’t stop (attaching image of the log).
Any idea to get this information?
Many thanks!
The function .ts:

tips: any;

getDataJSON() {
      return new Promise(resolve => {
        this.http.get('/assets/advices.json') 
          .subscribe((data) => {
            resolve(data);
            console.log(data);
           this.getDataJSON().then(data => {
              this.tips = data;
          }, err => {
            console.log(err);
          });
      });
    })
  }

html:

<button ion-button block (click)="getDataJSON()">Fetch External Data</button>%E2%80%8F%E2%80%8F%D7%9C%D7%9B%D7%99%D7%93%D7%94

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles