I need to pass an expression to a component that will be evaluated inside an component's template.
For example, component:
@Component({
selector: 'app-my-component',
...
})
export class MyComponent {
@Input items: MyClass;
@Input expression: String;
...
}
with component's template:
<div *ngFor="let item of items">
{{expression}}
</div>
Usage of MyComponent:
<app-my-component [items]="listOfItems" [expression]="'[item.id] item.name'">
</app-my-component>
As there will be more than one input, I would like to avoid usage of TemplateRef.
'[item.id] item.name'supposed to do? That doesn't look like an expression to me. You can't pass bindings around.[expression]=" '{"id":[item.id],"name": item.name}' "and use as expression.id and expression.name[expression]=" '[' + item.id + '] ' + item.name "