我有一个共享服务文件,该文件定义了一个类似于以下内容的变量:

export class SharedService {
    activeModal: String;
}

然后,我有一个导入服务并定义它的组件文件:
constructor(public sharedService: SharedService) {
}

在该组件的模板文件中,我检查模态的值:
<div *ngIf="sharedService.activeModal === 'login'"></div>

一切正常,但是在编辑器中,sharedService.activeModal ==='login'部分下有一条红色的蠕行,并将其悬停在该行上可显示此棉绒错误:
[Angular] Expected the operants to be of similar type or any
property sharedService of ModalComponent

有什么想法我做错了吗?

最佳答案

string的声明中尝试使用小写的String(原始类型,而不是包装对象类型activeModal)。

关于Angular 2 : "Expected the operants to be of similar type or any" linting error,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51736051/

10-09 20:42