Implementing Dynamic Views in Angular
Netanel Basal

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’;


selector: ‘app-sidebar’,

template: `


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




export class SidebarComponent implements AfterViewInit {

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

constructor( private _sidebarService : SidebarService ) {


ngAfterViewInit() {

this._sidebarService.vcr = this.container;



One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.