Created
September 22, 2016 21:18
-
-
Save glendaviesnz/40f2bcc1296b9b92ed1b25307f40a283 to your computer and use it in GitHub Desktop.
Angular 2 app root component with dynamic first child
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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