Created
February 9, 2018 15:09
-
-
Save petyosi/62454ef5cbdbc084310ebf86649ec408 to your computer and use it in GitHub Desktop.
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
@Component({ | |
selector: 'my-app', | |
template: ` | |
<div class="container-fluid"> | |
<div class="page-header"> | |
<h1>Creating AOT Friendly Dynamic Components with Angular 2</h1> | |
</div> | |
<div class="row"> | |
<div class="col-lg-12"> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Application Code</div> | |
<div class="panel-body"> | |
<div class="input-group"> | |
<span class="input-group-btn"> | |
<button type="button" class="btn btn-primary" (click)="grid.addDynamicCellComponent(selectedComponentType)">Add Dynamic Grid component</button> | |
</span> | |
<select class="form-control" [(ngModel)]="selectedComponentType"> | |
<option *ngFor="let cellComponentType of componentTypes" [ngValue]="cellComponentType">{{cellComponentType.name}}</option> | |
</select> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-lg-12"> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Library Code</div> | |
<div class="panel-body"> | |
<grid-component #grid></grid-component> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
` | |
}) | |
export class AppComponent implements OnInit { | |
@Input() componentTypes: any[] = [BlueDynamicComponent, GreenDynamicComponent, RedDynamicComponent]; | |
@Input() selectedComponentType: any; | |
ngOnInit(): void { | |
// default to the first available option | |
this.selectedComponentType = this.componentTypes ? this.componentTypes[0] : null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment