Can't use two-way binding ngModel in alertController


#1
let alert = this.alertCtrl.create({
        title: "abb",
        message:"Ababa.",
        buttons: [
          {
            text: 'no.',
            handler: data => {
              console.log("cancel")
             
            }
          },
          {
            text: 'yes',
            handler: data => {
                console.log(data);
                
                this.zone.run(()=>{
                  this.mention2="sis"
                  this.startDetail="should be changed dynamically"
                  console.log(this.startDetail);
                })
                
            
            }
          }
        ]
        })
        alert.present();

on html, I use <ion-searchbar [(ngModel)]=“startDetail” /> and

{{mention2}}

.
once chosen yes on dialog, it should be changed instantly, but docent’ work.
it applied only when I click(touch) searchbar changes applied…

#2

It really weird…

I changed alertController to modal.

let modal = this.modalCtrl.create(ConfirmationPage);
      modal.onDidDismiss(data => {
        this.startDetail="ab"
        this.mention2="abbb"
      });
      modal.present();

neither works.


#3

It isn’t supposed to work. You’d benefit from reading the Angular docs on how change detection works. A simple thing you can do is to call ChangeDetectorRef.detectChanges() after your modal is dismissed. That will update your startDetail field. But the best thing to do is to understand change detection. Simply put: Angular checks for changes after certain kinds of things happen, and updating a modal or an alert are not part of those things.