私の Angular アプリにはコンポーネントがあります:
import { MakeService } from './../../services/make.service';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-vehicle-form',
templateUrl: './vehicle-form.component.html',
styleUrls: ['./vehicle-form.component.css']
})
export class VehicleFormComponent implements OnInit {
makes: any[];
vehicle = {};
constructor(private makeService: MakeService) { }
ngOnInit() {
this.makeService.getMakes().subscribe(makes => { this.makes = makes
console.log("MAKES", this.makes);
});
}
onMakeChange(){
console.log("VEHICLE", this.vehicle);
}
}
しかし、「makes」プロパティに間違いがあります。どうすればいいのかわかりません...
ベストアンサー1
tsconfig.jsonを開いて設定するだけです
"compilerOptions": {
"strictPropertyInitialization": false,
...
}
コンパイルエラーを解消します。
そうでなければ、すべての変数を初期化する必要があり、少し面倒です