Я пытаюсь интегрировать LinkedIn login
в угловом 2, все они работают хорошо, но я получаю несколько ошибок в 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