【问题标题】:How to check in component.html if column type=1 display label text Active else display Not active?如果 column type=1 显示标签文本 Active else display Not active,如何检查 component.html?
【发布时间】:2020-09-07 19:30:46
【问题描述】:

我有对象名称 ReportControl 我遇到问题我无法检查与此对象相关的值

如果列类型为 1,则显示标签处于活动状态,否则在 reportcomponent.html 上显示标签未处于活动状态

对象ReportControl的数据如下

{"reportId":2028,"fieldName":"offilneURL","reportStatus":"HiddenColumn","columnType":1}

关于reportcomponent.ts

this._displayreport.GetReportControl(param2).subscribe((res: any) => {
        this.ReportControl = res;
        console.log("report control is" + JSON.stringify(this.ReportControl) );

      });

在 service.ts 上

  GetReportControl(id : string){
      return this.http.get<any[]>(this.url+ 'report/GetAllReportControl/id=' + id)
      .map(res=>res);

    }

reportcomponent.html

我需要检查列类型是否 = 1,然后显示带有文本活动的标签 否则显示文本未激活的标签。

文本处于活动状态的预期结果显示标签

【问题讨论】:

  • 你也可以加html吗?

标签: javascript typescript angular7 angular-directive angular-components


【解决方案1】:

这就是您在 html 中有条件地显示文本的方式,这是您所期望的吗?

<label>{{ReportControl.columnType == 1 ? 'Active' : 'Inactive'}}</label>

使用*ngIf

<label *ngIf="ReportControl.columnType == 1">Active</label>
<label *ngIf="ReportControl.columnType == 0">Inactive</label>

【讨论】:

  • 我可以使用 *ngIf 来做到这一点
猜你喜欢
  • 2021-01-10
  • 2021-10-28
  • 1970-01-01
  • 2018-09-15
  • 2014-08-12
  • 2019-04-06
  • 2012-11-08
  • 1970-01-01
  • 2019-09-12
相关资源
最近更新 更多