Angular 5 – “无法读取未定义的属性”
发布时间:2020-12-17 17:23:58 所属栏目:安全 来源:网络整理
导读:在Angular 5中,用于输入 input name="techSpecMeta.make" [(ngModel)]="techSpecMeta.make" type="text" class="form-control border-input" placeholder="Enter car brand" 得到错误 无法读取未定义的属性’make’ ????在Object.eval [作为updateDirectives
在Angular 5中,用于输入
<input name="techSpecMeta.make" [(ngModel)]="techSpecMeta.make" type="text" class="form-control border-input" placeholder="Enter car brand"> 得到错误 export class UserComponent implements OnInit { constructor(private vahinfo: VehicleInfo) {} ngOnInit() {} techSpecMeta: {}; onSave = function(vehicle,isValid: boolean) { this.vahinfo.saveVehicle(vehicle).subscribe(data => { console.log(data.data) },error => this.errorMessage = error) } } 解决方法techSpecMeta: {}; 在类型脚本中,这意味着声明类型为{}的属性,而不初始化值.它与: techSpecMeta: Object; 你应该这样做 techSpecMeta = {}; 要使绑定工作,您还需要属性make. techSpecMeta = {make: null}; 理想情况下,您将为TechSpecMeta创建一个类/接口 class TechSpecMeta { make: null; anotherProperty: null; } 并在您的组件中使用它 techSpecMeta = new TechSpecMeta(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |