我收到一条错误消息:成员'make'隐含有'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
我收到以下错误:
属性'make'没有初始值设定项,并且在构造函数中没有明确赋值。 at:'10,3'来源:'ts'代码:'2564'
使用特定类型声明您的变量make并初始化它
makes:any = [];
这就是你的代码应该如何。
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);
});