2017-11-14 8 views
0

ボタンをクリックするとcreatePlaylist()がトリガされると、関数はasd()を実行できません。私は同じ機能ですべてをやろうとしましたが、同じことができます。 console.log(resp)はログに記録しません。何故ですか?Angular2で機能が実行されない

subscribe()なし
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); 
    }); 
} 
+1

([角度2 HTTP GETを得ていない]の可能性のある重複https://stackoverflow.com/questions/41381200/angular-2-http-get-not-getting) – jonrsharpe

答えて

1

(またはforEach()または実際に観測可能な実行いくつかの他)観測は何もしません、彼らは怠け者なので、

this.http.post(url, body, { headers }).subscribe(resp => { 
    console.log(resp); 
}); 
関連する問題