错误讯息:会员'制作'隐含地有一个“任何”的类型

时间:2018-04-02 13:29:52

标签: angular typescript tslint

我收到错误讯息:会员'制作'隐含地有一个“任何”的类型。

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,我会收到以下错误:

  

财产'制造'没有初始化程序,并且在构造函数中没有明确赋值。 at:' 10,3'来源:' ts'代码:' 2564'

2 个答案:

答案 0 :(得分:0)

这就是你的代码应该如何。

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);

});

答案 1 :(得分:-1)

使用特定类型声明您的变量make并初始化它

makes:any = [];