Я следую всем шагам руководства по рекламным баннерам на Angular.io. Но в конце после всех настроек я получаю сообщение об ошибке от этого компонента и функции:
Ad-banner.component TS
loadComponent() {
this.currentAdIndex = (this.currentAdIndex + 1) % this.ads.length;
const adItem = this.ads[this.currentAdIndex];
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(adItem.component);
const viewContainerRef = this.adHost.viewContainerRef; ---->ERROR comes from this Line
viewContainerRef.clear();
const componentRef = viewContainerRef.createComponent(componentFactory);
(<AdComponent>componentRef.instance).data = adItem.data;
}
Я получаю журнал правильно, данные о героях поступают в домашний компонент, где я показываю рекламу, но не с ошибкой, так может ли кто-нибудь со мной разобраться?
ИЗМЕНИТЬ Основную директиву
import { Directive, ViewContainerRef } from '@angular/core';
@Directive({
selector: '[ad-host]'
})
export class AdDirective {
constructor(public viewContainerRef: ViewContainerRef) { }
}