Вручную вставить компонент материала в элемент HTML - PullRequest
0 голосов
/ 06 октября 2018

Как добавить в DivElement список компонентов материала, скажем, MaterialCheckboxComponent?

DivElement.children - это List<Element>, и я не вижу, как привести List<MaterialCheckboxComponent> к List<Element>.

Как мне добиться того, что делается с MaterialCheckboxComponent вручную?

1 Ответ

0 голосов
/ 07 октября 2018

https://webdev.dartlang.org/angular/note/faq/component-loading - раздел о динамическом добавлении компонентов

@Component(
  selector: 'ad-view',
  template: r'''
    This component is sponsored by:
    <template #currentAd></template>
  ''',
)
class AdViewComponent {
  final ComponentLoader _loader;

  AdViewComponent(this._loader);

  @ViewChild('currentAd', read: ViewContainerRef)
  ViewContainerRef currentAd;

  @Input()
  set component(ComponentFactory component) {
    _loader.loadNextToLocation(component, currentAd);
  }
}
...