map json con AngularHttpClient
Después de actualizar mi proyecto para usar elHttpClient
módulo en lugar deHttp
módulo, lo siguiente ya no funciona.
El problema esProperty json does not exist on type object
. Necesito obtener elitems
propiedad. ¿Cómo puedo conseguir esto
private loadLatestVideosForChannelId( channelId: string ): Promise<any[]> {
// load videos from youtube-data-api
let videos = this.http.get(
'https://www.googleapis.com/youtube/v3/search' +
'?key=' + this.apiKey +
'&channelId=' + channelId +
'&part=snippet,id' +
'&order=date' +
'&type=video' +
'&maxResults=3'
)
.pipe(
// if success
map( res => {
return res.json()['items']; // the problem
}),
// if error
catchError( (err) => {
console.log( "YouTube API Error > Cannot get videos for this channel :(" )
return null;
}),
take(1)
)
.toPromise() as Promise<any[]>;
return videos;
}