以角度形式获取[Object Object]并且下拉(选择)未设置为默认 0 索引。虽然在编辑的情况下一切正常。我需要为此创建页面初始化模型属性吗?
编辑: ngModelChange没有调用函数doNameChange。
零件:
export class User {
Id: number;
Name: string;
Gender: string;
}
this.user = {
Id: 0,
Name: '',
Gender: ''
}
doNameChange(event) {
debugger;
console.log(event); // logs model value
}
html:
<form (ngSubmit)="save(f.value, f.valid)" #f="ngForm" novalidate materialize>
<input id="Name" (ngModelChange)="doNameChange($event)" name="Name" #Name="ngModel" type="text" class="validate form-control" required minlength="3" [(ngModel)]="user.Name">
<select id="Gender" name="Gender" #Gender="ngModel" class="validate form-control" [(ngModel)]="user.Gender" required>
<option value="">-- Select Gender --</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</form>