Angular 5在运行时使用Oninit或ngAfterViewInit部分加载组件

时间:2018-01-15 16:03:00

标签: javascript angular typescript

我目前正在考虑在运行时加载一个组件,并在谷歌搜索之后来到这个页面。

我想知道是否可以在app.component.ts中对此进行编码以从HERE加载组件。

例如:

import { Component, OnInit, Directive, ViewContainerRef } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

    constructor(public viewContainerRef: ViewContainerRef) { }

    ngOnInit() {
        // CODE TO LOAD THE COMPONENT HERE
    }

}

可以使用 OnInit ngAfterViewInit 完成吗?如果是这样的话?

0 个答案:

没有答案