https://techoverflow.net/2018/02/17/how-to-fix-angular-typeerror-templateref-createembeddedview-is-not-a-function/

од, который я пытаюсь заставить работать (угловой 5):

  import { Component, ViewChild, TemplateRef, ViewContainerRef } from '@angular/core';

@Component({
  selector: 'vcr',
  template: `
    <template #tpl>
      <h1>ViewContainerRef</h1>
    </template>
    <div>Some element</div>
    <div #container></div>
  `,
})
export class VcrCmp {
  @ViewChild('container', { read: ViewContainerRef }) _vcr;
  @ViewChild('tpl') tpl: TemplateRef<any>;

  constructor(
    private viewContainerRef: ViewContainerRef
  ) {

  }

  ngAfterViewInit() {
    console.info(this.viewContainerRef);
    console.info(this._vcr);

    this._vcr.createEmbeddedView(this.tpl);
    this.viewContainerRef.createEmbeddedView(this.tpl);
  }
}

Проблема в том, что у меня это есть (templateRef.createEmbeddedView is not a function) ошибка и не очень понимаю, почему.

Этот код основан на этом примереhttps://netbasal.com/angular-2-understanding-viewcontainerref-acc183f3b682 так что я думаю, это должно сработать.

Что я делаю неправильно?

Ответы на вопрос(3)

Ваш ответ на вопрос