【问题标题】:Operator '>' cannot be applied to types '() => number' and 'number'运算符 \'>\' 不能应用于类型 \'() => number\' 和 \'number\'
【发布时间】:2023-02-11 13:45:29
【问题描述】:

我试图让这个 ngIf 在我的 html 文件中工作,它给了我这个错误,我不知道是什么导致了这个。有人可以解释一下吗?谢谢 运算符“>”不能应用于类型“() => number”和“number”。

```<td *ngIf = "boat.getBoatRating>35" > {{boat.getBoatName}} </td>```

我的班级模型

```export class BoatClass {
  private boatId: number;
  private boatName: string;
  private boatRating: number;

  constructor(boatId: number, boatName: string, boatRating: number) {
    this.boatId = boatId;
    this.boatName = boatName;
    this.boatRating = boatRating;
  }

  getBoatId(): number {
      return this.boatId;
    }
  getBoatName(): string {
        return "${this.boatName}";
      }
  getBoatRating(): number {
        return this.boatRating;
      }
}```

我的组件

```import { Component } from '@angular/core';
import { BoatClass } from "./models/boat-class.model";


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'angp';
  
  boatArr: BoatClass[] = [
  new BoatClass(100, "Boat1", 30),
  new BoatClass(200, "Boat2", 32),
  new BoatClass(300, "Boat3", 34),
  new BoatClass(400, "Boat4", 37),
  ]
}```

【问题讨论】:

  • boat.getBoatRating()&gt;35

标签: javascript html node.js angular typescript


【解决方案1】:

响应:getBoatrating 是一个函数。你必须像这样获取它
&lt;td *ngIf = "boat.getBoatRating()&gt;35" &gt; {{boat.getBoatName}} &lt;/td&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 2022-11-12
    相关资源
    最近更新 更多