请我正在尝试充实我正在进行的离子项目的注册页面尝试将我的 ([ngModel]) 绑定到我的组件中的对象属性。
让我只显示代码摘录,以便您了解
**Registration.ts** // This is my registration component
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-registration',
templateUrl: 'registration.html',
})
export class RegistrationPage {
newStaffInfo = {
username: "",
password: "",
rePassword: "",
email: "",
sex: ""
}
newStaffTemplateObject: Object = [
{
label: "Username",
field: this.newStaffInfo.username,
},
{
label: "Password",
field: this.newStaffInfo.password
},
{
label: "Re-enter Your password",
field: this.newStaffInfo.rePassword
},
{
label: "Email",
field: this.newStaffInfo.email
},
{
label: "Sex",
field: this.newStaffInfo.sex
},
];
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad RegistrationPage');
}
validateForm(){
console.log("Validate in this functin...");
}
}
这是我的 HTML 模板
<ion-content padding>
<form (ngSubmit)="validateForm()" #form="ngForm">
<ion-list>
<ion-item *ngFor="let item of newStaffTemplateObject">
<ion-label floating> {{item.label}} </ion-label>
<ion-input type="text" [(ngModel)]="item.field" name="item.label" #item.label="ngModel" required> </ion-input>
</ion-item>
<ion-item>
<button ion-button outline block full> Register </button>
</ion-item>
</ion-list>
</form>
<!-- For DEbugging puprpose only -->
{{newStaffInfo.username}} //This is suppose to reflect changes immediately
</ion-content>
即使使用上述设置,它也根本不起作用。我可以在这里做什么来使两个数据绑定工作