【问题标题】:How to get the class name of the data model in Angular? [duplicate]如何在 Angular 中获取数据模型的类名? [复制]
【发布时间】:2019-07-07 07:24:29
【问题描述】:

在 Angular 中使用此数据模型代码:

export class Car {
  brand: string;
  year: number;
  nameOfModel() => {
    // I need return here the name of class as a string: 'Car'
  }
}

我能以某种方式将类的名称作为字符串取回吗?

【问题讨论】:

  • @KristófTóth :如果模型具有“名称”属性,这在类内部如何工作?

标签: javascript angular data-modeling


【解决方案1】:

这对我有用:

export class Car {
    brand: string;
    year: number;
    nameOfModel: string = () => {
        return Car.name
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    相关资源
    最近更新 更多