17.10.2018 Views

Angular

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

@NgModule({<br />

imports: [ BrowserModule ],<br />

declarations: [ App, ChildComponent ],<br />

bootstrap: [ App ],<br />

entryComponents: [ChildComponent] // define the dynamic component here in module.ts<br />

})<br />

export class AppModule {}<br />

Plunker example<br />

Section 10.3: Rendered dynamically created component array<br />

on template HTML in <strong>Angular</strong> 2<br />

We can create dynamic component and get the instances of component into an array and finally rendered it on<br />

template.<br />

For example, we can can consider two widget component, ChartWidget and PatientWidget which extended the class<br />

WidgetComponent that I wanted to add in the container.<br />

ChartWidget.ts<br />

@Component({<br />

selector: 'chart-widget',<br />

templateUrl: 'chart-widget.component.html',<br />

providers: [{provide: WidgetComponent, useExisting: forwardRef(() => ChartWidget) }]<br />

})<br />

export class ChartWidget extends WidgetComponent implements OnInit {<br />

constructor(ngEl: ElementRef, renderer: Renderer) {<br />

super(ngEl, renderer);<br />

}<br />

ngOnInit() {}<br />

close(){<br />

console.log('close');<br />

}<br />

refresh(){<br />

console.log('refresh');<br />

}<br />

...<br />

}<br />

chart-widget.compoment.html (using primeng Panel)<br />

<br />

<br />

<br />

Chart<br />

Widget<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!