Skip to content

Instantly share code, notes, and snippets.

@petyosi
Created February 9, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petyosi/62454ef5cbdbc084310ebf86649ec408 to your computer and use it in GitHub Desktop.
Save petyosi/62454ef5cbdbc084310ebf86649ec408 to your computer and use it in GitHub Desktop.
@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