相关疑难解决方法(0)

为什么在类的构造函数中声明的属性不存在?

constructor (service: MyService) {}

ngOnInit() {
    this.service.init();
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我得到:-

Property `service` does not exist on type 'MyComponment'
Run Code Online (Sandbox Code Playgroud)

然而,如果我宣布serviceprivate它的工作原理。这里发生了什么?

——

[Angular 8.2.12,TypeScript 3.5.3]

typescript angular

0
推荐指数
1
解决办法
687
查看次数

标签 统计

angular ×1

typescript ×1