【问题标题】:How to set value of *ngFor dynamically in Angular2如何在Angular2中动态设置*ngFor的值
【发布时间】:2018-03-09 22:11:00
【问题描述】:

我想动态设置 '*ngFor' 的值。

我有一个类似的 div:<div *ngFor="let section of anyArr; let i = index">

我想要这样的上式声明:

<div *ngFor="let section of {{anyArr}}; let i = index">`

我想要 'dummyArr' 作为 .ts 文件中的 anyArr = myArr[0].Control[2]。 这在 Angular 2 中可行吗???

【问题讨论】:

    标签: html angular2-template angular2-forms angular2-directives


    【解决方案1】:

    您可以像这样在组件中使用 getter 来做到这一点:

    get anyArr() {
      return myArr[0].Control[2];
    }
    

    然后在模板中使用:

    <div *ngFor="let section of anyArr; let i = index">`
    

    【讨论】:

    • 我不知道我是否理解这个问题... get anyArr() 只是组件中的另一个函数,您可以从模板中调用它。
    猜你喜欢
    • 2017-06-09
    • 2016-04-06
    • 2016-10-17
    • 2017-11-16
    • 1970-01-01
    • 2016-11-25
    • 2017-12-18
    • 2016-09-07
    • 2016-10-11
    相关资源
    最近更新 更多