Can't read property input undefined?

Scenario:

The first login page, all sockets are downloaded from the web service. The user enters the username, password and selects the outlet and presses the "Submit" button. After authentication, the following page is displayed. There, the user logs out, eventually bringing up the login page. Now again, all exits are loaded from the web service. User selects outputs, bang, Cannot read properties 'input' of undefined error. I have no idea where to look, everything is in order, each element is loaded, especially the outputs.

Here is my coding:

login.ts:

  ionViewWillEnter() { this._flag = false; this._credits = 1; let loading = this._loadingCtrl.create({ content: 'Connecting to the server...' }); loading.present(); this._storage.ready().then(() => { this._outlets = []; this._storage.get('api').then((url) => { if (url !== null) { this._authSrv.setAPI(url); this._foodSrv.getOutlets(url).subscribe((_outlets) => { _outlets.forEach(outlet => { var item = new Outlet(outlet.OltCode, outlet.OltName); this._outlets.push(item); //I double checked items are getting pushed here this._flag = true; }); if (this._flag) { loading.dismiss(); } else { loading.dismiss().then(() => { this.openSettings(); }) } }) } }); }); } doLogin() { if (this._username !== undefined && this._password !== undefined && this._foodSrv.getOutletCode() !== undefined) { let loading = this._loadingCtrl.create({ content: 'Please wait...' }); loading.present(); this._authSrv.login(this._username, this._password).subscribe(data => { ... this._authSrv.getUserDetails(this._authSrv.getAPI(), this._username, this._password).subscribe(data => { ... this._navCtrl.setRoot('HomePage'); }); }); loading.dismiss(); }, (err) => { this.errorMsg("Invalid _username/_password !"); loading.dismiss(); }); } else if (this._username === undefined) this.errorMsg("Empty username !"); else if (this._password === undefined) this.errorMsg("Empty password !"); else if (this._foodSrv.getOutletCode() === '') this.errorMsg("Please select an outlet !"); } //I used this part so that the option is selected once it was clicked ngOnInit() { let root = this._viewCtrl.instance._navCtrl._app._appRoot; document.addEventListener('click', function (event) { let btn = <HTMLLIElement>document.querySelector('.remove-ok .alert-button-default:nth-child(2)'); let target = <HTMLElement>event.target; if (btn && target.className == 'alert-radio-label') { let view = root._overlayPortal._views[0]; let inputs = view.instance.d.inputs; for (let input of inputs) { if (input.checked) { view.instance.d.buttons[1].handler([input.value]); view.dismiss(); break; } } } }); } 

Options.ts:

 logout() { this.navCtrl.setRoot("LoginPage"); this.navCtrl.popToRoot(); } 

Scenario:

enter image description here

Update # 1:

I used this code to make a one-click selection Ionic2 Ion-select without OK and Cancel

I also found a problem where everything went wrong.

  let view = root._overlayPortal._views[0]; let inputs = view.instance.d.inputs; 

The first time the view is an AlertController, and then it was a ViewController. I still don’t know how to fix it. Any advice would be helpful. Thanks.

+1
source share

All Articles