简体   繁体   English

Angular 2中的动态绑定

[英]Dynamic binding in Angular 2

Basically I am looking for shorthand version of this: 基本上我正在寻找这样的简写版本:

<div class="">
{{listObject.firstHeaderKey.type === 'value' ? listObject.firstHeaderKey.key: item[listObject.firstHeaderKey.key}}
</div>

My data could either be a string or an expression ie 我的数据可以是字符串或表达式,即

<div *ngFor="let mix of mixList">
    <div>
    {{mix}}
    </div>
</div>

mix can either be " 'text' " or "obj[text]" and accordingly the template should evaluate. mix可以是“'text'”或“ obj [text]”,因此模板应进行评估。

According to best practisies you should do this in your typescript file 根据最佳实践,您应该在打字稿文件中执行此操作

mix: any;
this.mix === 'value' ? listObject.firstHeaderKey.key : 
                       item[listObject.firstHeaderKey.key]

And template should be something like this: 模板应该是这样的:

<div>
{{mix}}
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM