【问题标题】:Error message: Member 'makes' implicitly has an 'any' type错误消息:成员“makes”隐式具有“any”类型
【发布时间】:2019-03-20 08:42:25
【问题描述】:

我收到一条错误消息:成员“makes”隐含地具有“any”类型。

export class VehicleFormComponent implements OnInit {
makes;
constructor(private makeService:MakeService) { }
ngOnInit() {
this.makeService.getMakes().subscribe(makes=>{
  this.makes = makes
  console.log("MAKES",this.makes);
});

已编辑:

如果我添加 makes:any[]; 而不是 make:any 我会收到以下错误:

属性“makes”没有初始化器,也没有在构造函数中明确分配。在:'10,3' 来源:'ts' 代码:'2564'

【问题讨论】:

    标签: angular typescript tslint


    【解决方案1】:

    用特定类型声明你的变量并初始化它

    makes:any = [];
    

    【讨论】:

    • @mohamedismail 通过初始化尝试如上
    【解决方案2】:

    你的代码应该是这样的。

    export class VehicleFormComponent implements OnInit {
    
    makes: any;
    
    constructor(private makeService:MakeService) { }
    
    ngOnInit() {
    
    this.makeService.getMakes().subscribe(makes=>{
      this.makes = makes
      console.log("MAKES",this.makes);
    
    });
    

    【讨论】:

      猜你喜欢
      • 2021-01-13
      • 2018-09-23
      • 2018-09-25
      • 2017-11-30
      • 2022-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      相关资源
      最近更新 更多