当按钮单击触发createPlaylist()时,该函数无法执行asd()。我尝试在同一个功能上完成所有操作,但我得到了同样的功能。 console.log(resp)从不记录。那是为什么?
createPlaylist(token:string = localStorage.getItem('myToken')) {
const url = `https://api.spotify.com/v1/users/${this.currentUser}/playlists`;
const headers = new Headers();
headers.append('Authorization', 'Bearer ' + token);
headers.append('Content-Type', 'application/json');
const body = {
'name': 'searchDDD playlist'
};
this.http.post(url, body, { headers } )
.subscribe(res => {
console.log(res.json().name);
console.log(res.status);
this.playlistID = res.json().id;
this.asd();
});
}
asd(token:string = localStorage.getItem('myToken')){
const url = `https://api.spotify.com/v1/users/${this.currentUser}/playlists/${this.playlistID}/tracks?`;
const body = {'uris': ['spotify:track:4iV5W9uYEdYUVa79Axb7Rh',
'spotify:track:1301WleyT98MSxVHPZCA6M']};
const headers = new Headers();
headers.append('Authorization', 'Bearer ' + token);
headers.append('Content-type', 'application/json');
this.http.post(url, body, { headers } ).map(resp => {
console.log(resp);
});
}
答案 0 :(得分:1)
没有"1.39.25.1".succ #=> "1.39.25.2"
(或subscribe()
或其他一些实际执行observable的人)observables将不会做任何事情,因为它们是懒惰的
forEach()