Ionic popup onTap issue

Unable to access ng-model in $ionicPopup template.

$scope.dashboard.addMoreModes = function() {
$scope.data = {};

  // An elaborate, custom popup
  var myPopup = $ionicPopup.show({
    template: '<ion-radio ng-model="data.modes" ng-value="item.value" ng-repeat="item in dashboard.paymentModes">{{item}}</ion-radio>',
    title: 'Add Payment Modes',
    subTitle: 'Select Mode',
    scope: $scope,
    buttons: [{
        text: 'Cancel'
      },
      {
        text: '<b>Add</b>',
        type: 'button-positive',
        onTap: function(e) {
          console.log($scope.data.modes);
        }
      }
    ]
  });

  myPopup.then(function(res) {
    console.log('Tapped!', res);
  });
};

In the log, data.modes is undefined. How do I access it?

Hi @aknituk,

I have tried your code. And I am not getting undefined at console.log() of onTap: event. But I am getting undefined at myPopup.then() function.

I have found the root cause as well. You need to return the value from onTap: event.

onTap: function(e) {
            return $scope.data.modes;
            console.log($scope.data.modes);
          } 

This is the sample code for the same. Hope this answer helps you finding the solution.

Feel free to mark it as solution if you find it worthy.

1 Like