我正在尝试编译此代码,但它得到错误....
. html…
<div *ngIf="(dateObj | date:'h') >= 5; else elseBlock2">
<h2>this is if</h2>
</div>
<ng-template #elseBlock2>
<h2>else block</h2>
</ng-template>
…
.ts
export class AppComponent {
title = 'weather-app';
dateObj:number = Date.now();
}
误差
error TS2365: Operator '>=' cannot be applied to types 'string' and 'number'.
6 <div *ngIf="(dateObj | date:'h') >= 5; else elseBlock2">
~~~~~~~~~~~~~~~~~~~~~~~~
src/app/app.component.ts:5:16
5 templateUrl: './app.component.html',
~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AppComponent.
当我在另一个项目之前做这种类型的过程时,它可以正常工作,但在这个项目中得到这个错误。请帮帮我
实际问题是日期。现在不是返回数字而是返回日期格式所以如果你想比较小时和5只需将5输入字符串格式
if(dateobj>'5'){
console.log("done")
}
最后我得到了这个问题的解决方案:
实际上问题是在我的工作空间,当我改变我们的工作空间时,这段代码正常工作。此代码中没有任何错误。