Implementing Dynamic Views in Angular
Netanel Basal
1.1K11

Netanel Basal simple and sweet article to explain edge cases as always. Good work.

In first example can sidebar component be written like this instead?

import { Component, AfterViewInit, ViewChild, ViewContainerRef } from ‘@angular/core’;

import { SidebarService } from ‘../sidebar.service’;

@Component({

selector: ‘app-sidebar’,

template: `

<div>

<ng-container #container></ng-container>

</div>

`

})

export class SidebarComponent implements AfterViewInit {

@ViewChild(‘container’, { read: ViewContainerRef }) container;

constructor( private _sidebarService : SidebarService ) {

}

ngAfterViewInit() {

this._sidebarService.vcr = this.container;

}

}