我有一个共享服务文件,它定义了一个像这样的变量:
export class SharedService {
activeModal: String;
}
然后我有一个导入服务并定义它的组件文件:
constructor(public sharedService: SharedService) {
}
在该组件的模板文件中,我检查模态的值:
<div *ngIf="sharedService.activeModal === 'login'"></div>
一切正常,但在编辑器中,sharedService.activeModal === 'login' 部分下方有一条红色波浪线,将鼠标悬停在它上面会显示此 linting 错误:
[Angular] Expected the operants to be of similar type or any
property sharedService of ModalComponent
知道我做错了什么吗?
最佳答案
在 activeModal
的声明中尝试使用小写的 string
(原语,而不是包装对象类型 String
)。
关于 Angular 2 : "Expected the operants to be of similar type or any" linting error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51736051/