2016-12-21 49 views
0

綁定我試圖綁定用戶名圖像URL,我通過Facebook從Facebook API得到登錄後angular2模板HTML,但它並沒有得到解決。任何一個有一個解決方案,數據從Facebook API中的角2

facbooklogin.component.ts

 FB.api('/me',function(response){ 
      this.username= response.name; 
     }); 

     FB.api(
     "/"+resp.authResponse.userID+"/picture", 
     function (response) { 
     if (response && !response.error) { 
      this.profileImg=response.data.url; 
     } 
     }); 

facebooklogin.component.html

<img *ngIf="authorized" [src]="profileImg"> 
      <h2>Hello {{username}}</h2> 

回答

1

這是因爲你的usernname和IMAGEURL在不同的上下文。使用箭頭功能。

FB.api('/me',(response)=>{ 
      this.username= response.name; 
}); 
+0

謝謝。明白了,愚蠢的錯誤:) – Mustafa