领英2 [英] Linkedin with angular 2
本文介绍了领英2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将LinkedIn login
集成到angular 2中,但一切正常,但是在webpack中我遇到的错误很少,以下是我的代码以及所得到的错误:
I am trying to integrate LinkedIn login
in angular 2, all are working fine, but I am getting few errors in webpack, below is my code and the errors I am getting:
//linkedin.component.ts
constructor(private zone: NgZone) {
window.angularComponentRef = {
zone: this.zone,
componentFn: () => this.onLinkedInLoad(),
component: this
};
}
ngOnInit() {
// Creating script tag with linkedin src and required api details
var linkedinEle = document.createElement('script');
linkedinEle.type = 'text/javascript';
linkedinEle.src = 'http://platform.linkedin.com/in.js';
linkedinEle.innerHTML = 'api_key: xxxxxxxxxxx \n authorize: true \n onLoad: onLinkedInLoad';
document.head.appendChild(linkedinEle);
}
// this will called when the linkedin api gets load
onLinkedInLoad() {
IN.Event.on(IN, "auth", function() {
console.log('Hell yeah');
});
}
// index.html
function onLinkedInLoad() {
window.angularComponentRef.zone.run(function () { window.angularComponentRef.componentFn()})
}
一切正常,但在webpack中出现此错误:
This all are working fine, but getting this errors in webpack:
1. Property 'angularComponentRef' does not exist on type 'Window'.
2. Cannot find name 'IN'.
所以我想我可以通过声明为declare let IN: any
来解决它,但是没有运气.
So I thought I can resolve it by declaring it like declare let IN: any
but no luck.
推荐答案
请改用window ['angularComponentRef']和window ['IN']或使用这两个字段扩展window界面
Use window['angularComponentRef'] and window['IN'] instead or extend the window interface with this two fields
这篇关于领英2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文