acloD128
acloD128

Reputation: 103

Scope of 'this' on onTap and on popUp in ionic is 'undefined'

I want to show a popUp in ionic, which does not allow the user to exit when he hasn't entered some input. Right now I'm using this here:

public showOwnIdentifierPrompt() {
      // Prompt popup code
      var promptPopup = this.$ionicPopup.prompt({
        title: this.floor_name,
        template: `<input ng-model="$ctrl.customFloorName"></input>`,
        scope: this.$scope,
        buttons: [
          {
            text: this.cancel,
            type: 'button-clear button-balanced',
            onTap: function(e) {
              // Cancel creation
              return false;
            }
          },
          {
            text: this.save,
            type: 'button-clear button-balanced',
            onTap: () => {
              // Create new floor
              return true;
            }
          }
        ]
      });

      promptPopup.then((res) => {
        if (res) {
          this.addNewFloor(this.customFloorName);
        }
      })
}

In the save onTap() event handler, I would like to access this.customFloorName from my class, to decide whether the user entered input. But it is always undefined. What can I do?

Upvotes: 0

Views: 266

Answers (1)

Mohit Saxena
Mohit Saxena

Reputation: 1449

You can get value on Save with below code :

 var value = this.scope.$ctrl.customFloorName;

Upvotes: 1

Related Questions