我试图整合角2 LinkedIn login
,所有工作正常,但我得到的的WebPack几个误区,下面是我的代码和我得到的错误:LinkedIn与角2
//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这样的错误:
1. Property 'angularComponentRef' does not exist on type 'Window'.
2. Cannot find name 'IN'.
所以我想我可以通过声明它像declare let IN: any
但没有运气解决。
包括你的代码在ngAfterViewInit,而不是ngOnInit – Niyaz
好的,但问题仍然存在 –
将你的custruter中的东西移动到ngAfterViewInit – Niyaz