2016-09-09 6 views
0

私のAngular2サービスが、linkedinスクリプトが提供するLinkedIN javascript SDKを使用しようとしています。機能は、データを取得し、それを返すために動作しますが、私は私は私はそれがローカルに設定されていないlinkedinInfo = dataを設定するときに問題があると思わバックlinkeidn変数をローカルに割り当てるウィンドウ関数を取得する

export class LinkedInAuthService { 

constructor(

) { 

} 

linkedInAuthorization() { 
    window['IN'].User.authorize(); 
    window['IN'].Event.on(window['IN'], 'auth', this.getLinkedInUserInfo); 
} 
getLinkedInUserInfo() { 
    let linkedinInfo:any; 
    window['IN'] 
     .API 
     .Raw() 
     .url("/people/~:(firstName,lastName,emailAddress,industry,specialties,positions)?format=json") 
     .result(function(data:any){ 
      console.log(data) //logs data correctly 
      linkedinInfo = data 
     }); 
    console.log(linkedinInfo) // undefined 
} 

AuthLinkedInUserforGlx() { 
    console.log(localStorage.getItem('linkedinInfo')) 
} 
} 

から得たデータをローカル関数の変数を設定することはできません、だけではない、それはローカルにする方法がわから

+0

「データを:いずれかが」働いていた、これはタイプミスでしょうか? – Darkrum

+0

@Darkrumは問題を引き起こしていません。 – pwborodich

+0

im curios then:どうしますか? – Darkrum

答えて

0

これは私にとって

export class LinkedInService { 
IN = window['IN']; 
userProfile: Object; 
constructor() { 
    this.userProfile = JSON.parse(localStorage.getItem('profile')) 
    this.IN.Event.on(this.IN, 'auth', this.getLinkedInUserInfo); 
    console.log('end of constructor') 
} 

linkedInAuthorization(){ 
    this.IN.User.authorize(); 
    console.log('end of linkedInAuthorization service') 
} 

getLinkedInUserInfo() { 
    this.IN.API.Raw() 
     .url("/people/~:(firstName,lastName,emailAddress,industry,specialties,positions)?format=json") 
     .result((data:any) => { 
      localStorage.setItem('profile', JSON.stringify(data)); 
      this.userProfile = data; 
     }); 
    console.log('end of getLinkedInUserInfo service'); 
    this.AuthLinkedInOnGlx 
} 

AuthLinkedInOnGlx(){ 

} 



} 
関連する問題