Reputation: 11
this.http.get(‘assets/data/subtitles.json’).map(res => res.json()).subscribe(data => {
this.subtitles = data;
});
This is ionic v3 localJSON read code, I have used.
but ionic V3 type not supported to ionic V4
Upvotes: 1
Views: 1975
Reputation: 43
Alternatively you can read the json as an import,
import * as subtitleJson from 'assets/data/subtitles.json';
Typescript may complain about the import not matching your type, so casting it as any
works,
const subtitles = subtitleJson as any;
Upvotes: 0
Reputation: 159
You can use fetch instead.
fetch('assets/data/subtitles.json').then(async res => {
this.subtitles = await res.json();
});
Upvotes: 2