I've come to a solution but I think this might not fill well for everyone needs. First of all treat nested components childs (after all, ng-content is nothing more than that) is very easy on React world and I think that it would be very nice to have a more robust solution for Angular too.
My solution is based on Material Angular Icon, the code you'll find here:
https://github.com/angular/material2/blob/master/src/lib/icon/icon.ts
Following MatIcon approach, I wish to create an icon component where the name of desired icon is passed by ng-content like arrow-top.
Therefore I wish to observe whenever ng-content changes so that I can update the span classname.
The solutions is simply linking the data present into ng-content to an @Input followed by a getter.
Thus, whenever the ng-content changes Angular will update its component input too.
Hope this looks clear.
@Component({
selector: 'fa-icons',
template: `
<span #templateRef class="template">
<ng-content></ng-content>
</span>
<span [className]="iconName" [ngStyle]="ngStyle">
</span>
`,
styles: [`
:host > span.template {
display: none;
}
`]
})
export class FaIconsComponent {
@ViewChild('templateRef') templateRef: ElementRef;
@Input() name: String;
@Input() ngStyle: StyleSheetList;
@Input()
get iconName() {
const text = this.templateRef.nativeElement.textContent.trim();
return `fa-${text}`;
}
}