相关疑难解决方法(0)

如何将表达式作为Angular2中的输入传递给组件?

我需要将表达式传递给将在组件模板中进行求值的组件.

例如,组件:

@Component({
  selector: 'app-my-component',
  ...
})
export class MyComponent {
  @Input items: MyClass;
  @Input expression: String;
  ...
}
Run Code Online (Sandbox Code Playgroud)

使用组件的模板:

<div *ngFor="let item of items">
  {{expression}}
</div>
Run Code Online (Sandbox Code Playgroud)

MyComponent的用法:

<app-my-component [items]="listOfItems" [expression]="'[item.id] item.name'">
</app-my-component>
Run Code Online (Sandbox Code Playgroud)

由于将有多个输入,我想避免使用TemplateRef.

angular2-components angular

9
推荐指数
1
解决办法
4282
查看次数

标签 统计

angular ×1

angular2-components ×1