在 上<ng-template>构建自定义属性



我有一个组件,它有两个@Inputs: @Input() identificador: string; @Input() descripcion: string;

我将属性名称作为字符串传递,例如("nombre"(

<ng-template ng-option-tmp let-item="item">
    item.{{descripcion}} <br/>
    <small class="text-muted">item.{{identificador}}</small>
</ng-template>

我有这个ng-template,我想构建一个自定义属性,例如在我想要的 ng 模板中:

item.nombre这是一个例子,因为我希望它基于我发送的值。

我尝试这样做:item.{{descripcion}}但它不起作用

无论如何,我该怎么做?

我想将您的属性括在方括号中应该可以:

{{ item[descripcion] }}

因为这就是我们在 JavaScript 中访问动态属性的方式。

最新更新