Hi, someone has worked with the API Spotify , I'm trying to show all the albums of the artist but he gives me a bad request
, do you know why? I have reviewed and I can not find the error.
-------------- SpotifyService.ts ----------
import {Injectable} from '@ angular / core';
import {Http, Headers} from '@ angular / http';
import 'rxjs / add / operator / map';
@Injectable ()
export class SpotifyService {
private searchUrl: string;
private artistUrl: string;
private albumsUrl: string;
constructor(private _http:Http){
}
searchMusic(str:string, type='artist'){
this.searchUrl = 'https://api.spotify.com/v1/search?query='+str+'&offset=0&limit=20&type='+type+'&market=US';
return this._http.get(this.searchUrl)
.map(res => res.json());
}
getArtist(id:string){
this.artistUrl = 'https://api.spotify.com/v1/artists/'+id;
return this._http.get(this.artistUrl)
.map(res => res.json());
}
getAlbums(artistId:string){
this.albumsUrl = 'https://api.spotify.com/v1/artists/'+artistId+'/albums';
return this._http.get(this.albumsUrl)
.map(res => res.json());
}
}
--------- artist.component.ts ------
import {Component, OnInit} from '@ angular / core';
import {SpotifyService} from '../services/ spotify.service';
import {Artist} from '../../../ artist';
import {Album} from '../../../ album';
import {ActivatedRoute} from '@ angular / router';
@Component ({
moduleId:module.id,
selector: 'artist',
templateUrl: 'artist.component.html',
})
export class ArtistComponent implements OnInit {
id:string;
artist: Artist[];
albums:Album[];
constructor(
private _spotifyService:SpotifyService,
private _route:ActivatedRoute){
}
ngOnInit(){
this._route.params
.map(params => params['id'])
.subscribe((id) => {
this._spotifyService.getArtist(id)
.subscribe(artist => {
this.artist = artist;
})
this._spotifyService.getAlbums(id)
.subscribe(albums => {
this.albums = albums.items;
})
})
}
}
---------- artist.component.html -----------
<div class="row">
<div *ngFor=" let album of albums">
<h3> {{album.name}} </h3>
</div>
</div>