I want to be able to use the innerHtml of component tag before it will be replaced with component template. Hard to explain to be honest, here is an example.
Here is component(basically it is modal popup of bootstrap):
@Component({
selector: 'div.modal[show]',
template: require('./popup.component.html')
})
export class PopupComponent implements OnInit, OnChanges, OnDestroy {
@Input() show: boolean;
@Input() headerText: string;
body: string;
constructor(private el: ElementRef, private renderer: Renderer) {
// get the body of tag before replacement with it's template and assign it to this.body somehow.
}
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges) {
$(this.el.nativeElement).modal({
show: changes["show"].currentValue,
keyboard: false
});
}
ngOnDestroy() {
$(this.el.nativeElement).data("modal", null);
}
}
And its template:
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
{{headerText}}
</div>
<div class="modal-body">
{{body}} // Body have to be placed here
</div>
</div>
</div>
And its usage:
<div class="modal" [show]="true" [headerText]="'Edit standard field'">
<span>Something that have to be placed in div with class - modal-body</span>
</div>
And somewhere else:
<div class="modal" [show]="true" [headerText]="'Edit standard field'">
<h2>Something else that have to be placed in div with class - modal-body</h2>
</div>
So basically I am trying to get <span>Something else that have to be placed in div with class - modal-body</span>
and replace the - {{body}}
with it. Any idea how to achive it?
Hello world
" and to make separate component for that is great overhead.) – Maris Sep 14 '16 at 12:51Hello world
', or - 'Nothing here yet!' as well as some complex logic. Do you suggest to create separate component even for - 'Nothing here!'? – Maris Sep 14 '16 at 13:00Hello world