我试图让这个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),
]
}```
1条答案
按热度按时间wwwo4jvm1#
响应:getBoatrating是一个函数,必须像这样获取它
<td *ngIf = "boat.getBoatRating()>35" > {{boat.getBoatName}} </td>