错误消息:成员 'makes' 隐式具有 'any' 类型
Error message: Member 'makes' implicitly has an 'any' type
我收到一条错误消息:成员 '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
,我会收到以下错误:
Property 'makes' has no initializer and is not definitely assigned in the constructor. at: '10,3' source: 'ts' code: '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);
});
我收到一条错误消息:成员 '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
,我会收到以下错误:
Property 'makes' has no initializer and is not definitely assigned in the constructor. at: '10,3' source: 'ts' code: '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);
});