获取窗口函数在本地分配变量
Getting Window function to assign variable locally
我试图让我的Angular2服务使用LinkedIN javascript SDK,该SDK是由LinkedIN提供的脚本加载的。该功能用于获取数据并返回数据但我不能将本地函数变量设置为我从链接
返回的数据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'))
}
}
我认为问题是当我设置linkedinInfo = data
时它没有在本地设置它,只是不确定如何使它成为本地
这对我有用
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 (){
}
}
相关文章:
- 在运行时使用预先确定的对象分配变量
- 重新分配变量和重新定义之间的性能差异
- Javascript:在对象中分配变量时命名函数的好处
- Angularjs 控制器在服务方法返回之前从服务中分配变量
- 在 JavaScript 中的 for 循环中重新分配变量的目的是什么?
- 按设置的数量拆分字符串,并为拆分分配变量
- 嵌套的 if/else 语句讨论了分配变量.我已经这样做了,但它仍然不起作用
- 有没有理由不在 while 块声明中分配变量
- JSON - 访问 JSON 数组并分配变量
- Angular2 火力基地检索并分配变量
- 是否可以在运行依赖项之前在 gulp 任务中分配变量
- 在 JS 中的 for 循环中重新分配变量是什么意思
- 使用多种组合分配变量的最佳方法是什么
- 使用函数从字符串中分配变量名称
- 如何调用chrome.storage.sync.get并在页面加载时分配变量
- 在JavaScript中用冒号分配变量的语法有效吗
- 带有单选按钮的If语句不分配变量
- 正在从内部回调中分配变量
- Javascript在匿名函数中分配变量的值
- 使用jQuery分配变量类型时出错