1

I have a nav button that should show a popover

<ion-nav-buttons side="secondary">
    <button class="button button-icon icon ion-more" ng-click="openPopover($event)"></button>
</ion-nav-buttons>

and this is the controller

.controller('MyController', ['$scope','$ionicPopover', function($scope, $ionicPopover) {

    $ionicPopover.fromTemplateUrl('popover.html', {
      scope: $scope
    }).then(function(popover) {
      $scope.popover = popover;
    });
    $scope.openPopover = function($event) {
      $scope.popover.show($event);
    };
    $scope.closePopover = function() {
      $scope.popover.hide();
    };
    $scope.$on('$destroy', function () {
        $scope.popover.remove();
    });

}])

but when I click on the nav button I face the TypeError: Cannot read property 'show' of undefined at Scope.$scope.openPopover

here is the template which I have in the same project folder

<ion-popover-view>
  <ion-content>
    <div class="list">
      <label class="item item-input" ng-click="addFavorite(dish.id)">
        <div class="input-label">
          Add To Favorites
        </div>
      </label>
      <label class="item item-input" ng-click="openModal()">
        <div class="input-label">
          Add A Comment
        </div>
      </label>
    </div>
  </ion-content>
</ion-popover-view>
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123

2 Answers2

1

Fiddle with the expected behavior.

<div ng-click="openPopover($event)">
   Click to open popover
</div>

<script id="popover.html" type="text/ng-template">
   <ion-popover-view>
    <ion-header-bar>
       <h1 class="title">My Popover Title</h1>
    </ion-header-bar>
    <ion-content>
          Hello!
    </ion-content>
   </ion-popover-view>
</script>

The only situation I can think of is that you don't have the template with id "popover.html" defined.

tpsilva
  • 1,463
  • 1
  • 14
  • 24
0

Most probably the problem here is that the popover.html file is saved somewhere in a subfolder like 'templates' or similar and the controller referring to the html file has not a full qualified path respectively the script just does not find the file popover.html.

Marco P.
  • 81
  • 5