Angular - Type 'string' is not assignable to type 'boolean'

前端 未结 1 1434
不知归路
不知归路 2021-02-19 23:26

Angular 4.3.1
Angular CLI 1.2.3
Typescript 2.3.4

Component Typescript file:

public saveName: string;
public overwrite: boolean;

相关标签:
1条回答
  • 2021-02-19 23:47

    Try *ngIf="!overwrite && !!saveName" to cast saveName to a boolean

    The reason TypeScript gives for the error is roughly: you are using a string where you should be using a boolean.

    The reason I think that it only happens in that circumstance is because if you have true || anything only the first will be evaluated (because if the first is true the whole expression will true regardless of the rest)

    0 讨论(0)
提交回复
热议问题