首页 > 解决方案 > 建立自定义属性

问题描述

我有一个有两个@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-template 中构建一个自定义属性:

item.nombre这是一个示例,因为我希望以我发送的值为基础。

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

无论如何我该怎么做?

标签: angular

解决方案


我想将您的财产括在方括号中应该可以:

{{ item[descripcion] }}

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


推荐阅读