Skip to content

Instantly share code, notes, and snippets.

@glendaviesnz
Created September 22, 2016 21:18
Show Gist options
  • Select an option

  • Save glendaviesnz/40f2bcc1296b9b92ed1b25307f40a283 to your computer and use it in GitHub Desktop.

Select an option

Save glendaviesnz/40f2bcc1296b9b92ed1b25307f40a283 to your computer and use it in GitHub Desktop.
Angular 2 app root component with dynamic first child
import { Component, Input, ElementRef } from '@angular/core';
@Component({
selector: 'app',
template: '<dynamic-component [componentName]="componentName"></dynamic-component>'
})
export class AppComponent {
public componentName: string;
constructor(elm: ElementRef) {
// can't get @Input from root component so need to get value from raw
// element attribute
this.componentName = elm.nativeElement.getAttribute('componentName');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment