1

ポップオーバーを表示するナビゲーションボタンがあります

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

そしてこれがコントローラー

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

}])

しかし、ナビゲーションボタンをクリックすると、TypeError: Cannot read property 'show' of undefined at Scope.$scope.openPopover

これは、同じプロジェクトフォルダーにあるテンプレートです

<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>
4

2 に答える 2

1

予想される動作をいじります。

<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>

私が考えることができる唯一の状況は、ID「popover.html」が定義されたテンプレートがないことです。

于 2016-08-23T14:34:32.263 に答える
0

おそらくここでの問題は、popover.html ファイルが「templates」などのサブフォルダーのどこかに保存されており、html ファイルを参照するコントローラーに完全修飾パスがなく、スクリプトがファイル popover.html を見つけられないことです。 .

于 2017-05-16T14:16:40.507 に答える