无法读取未定义的属性“输入”?

时间:2017-04-26 13:32:23

标签: angular ionic2

情景:

首次登录页面,所有出口都是从Web服务加载的。用户输入用户名,密码并选择插座,然后单击“提交”。经过身份验证后,将显示下一页。用户注销,最终带来登录页面。 现在再次从Web服务加载所有出口。用户选择出口,爆炸,错误Cannot read properties 'input' of undefined。我不知道在哪里可以看到一切都很好,每个元素都被加载,特别是插座。

这是我的编码:

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();
  }

截屏:

enter image description here

更新#1:

我使用此代码只需点击Ionic2 Ion-select without OK and Cancel

即可进行选择

我也发现了它出错的问题。

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

第一次,view是一个AlertController,接下来是一个ViewController。我仍然不知道如何纠正这个问题。任何意见将是有益的。感谢。

0 个答案:

没有答案