角度2:“预期操作员为相似类型或任何其他类型”掉毛错误

yod*_*alr 8 typescript eslint angular

我有一个共享服务文件,它定义了一个类似于此的变量:

export class SharedService {
    activeModal: String;
}
Run Code Online (Sandbox Code Playgroud)

然后,我有一个导入服务并定义它的组件文件:

constructor(public sharedService: SharedService) {
}
Run Code Online (Sandbox Code Playgroud)

在该组件的模板文件中,我检查模态的值:

<div *ngIf="sharedService.activeModal === 'login'"></div>
Run Code Online (Sandbox Code Playgroud)

一切正常,但是在编辑器中,sharedService.activeModal ==='login'部分下有一条红色的蠕动线,并将其悬停在该行上将显示此掉毛错误:

[Angular] Expected the operants to be of similar type or any
property sharedService of ModalComponent
Run Code Online (Sandbox Code Playgroud)

有什么想法我做错了吗?

Mat*_*hen 14

在的声明中尝试使用小写字母string(原始类型,而不是包装对象类型StringactiveModal