【发布时间】: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()>35
标签: javascript html node.js angular typescript