Omr*_*ian 5 ionic-framework ionic2 angular2-forms ionic3
我有一个表格连接到模型NgModel如下:
<form #orderForm="ngForm" (ngSubmit)="onSubmit(orderForm)">
<ion-list class="contact_view">
<ion-item>
<ion-label stacked>{{ 'ADDRESS_LINE_1' | translate }}</ion-label>
<ion-input type="text" required placeholder="{{ 'ADDRESS_LINE_1_PLACEHOLDER' | translate }}" clearInput="true" name="addressLineOne" [(ngModel)]="order.addressLineOne"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>{{ 'ADDRESS_LINE_2' | translate }}</ion-label>
<ion-input type="text" placeholder="{{ 'ADDRESS_LINE_2_PLACEHOLDER' | translate }}" clearInput="true" name="addressLineTwo" [(ngModel)]="order.addressLineTwo"></ion-input>
</ion-item>
....
....
....
</ion-list>
</form>
Run Code Online (Sandbox Code Playgroud)
当我将它用作从视图到模型的一个方向绑定时,这对我来说效果很好.
现在,我希望能够从代码更新输入值,如下所示:
ionViewDidEnter() {
// attempt to load order from memory
this.storageService
.get<Order>(StorageKeys.ShippingDetails)
.then(order => {
// if order was loaded
if (order) {
// test
this.order.addressLineOne = "aaaa"; // test
// update UI components
//this.changeDetectorRef.markForCheck(); // not working
//this.changeDetectorRef.detectChanges(); // not working
// run inside ngZone to update UI
//this.ngZone.run(() => {
// init order from memory
//this.order.addressLineOne = "bbbb"; // not working
// });
}
});
}
Run Code Online (Sandbox Code Playgroud)
在AddressLineOne当输入一个专注才会更新.
我试过了changeDetectorRef.markForCheck(),detectChanges()然后在里面跑ngZone- 但没有那些工作.
// THIS LINE WORKS
this.order.addressLineOne = "aaba";
this.storageService
.get<Order>(StorageKeys.ShippingDetails)
.then(order => {
// if order was loaded
if (order) {
// THIS LINE DOESN"T WORK
this.order.addressLineTwo = "aaaa";
// update UI components
this.changeDetectorRef.markForCheck();
}
});
Run Code Online (Sandbox Code Playgroud)
从异步回调更新模型时,它不起作用.
有人能指出我正确的方向吗?
| 归档时间: |
|
| 查看次数: |
505 次 |
| 最近记录: |