2016-08-23 31 views
0

我有一个导航按钮应该表现出酥料饼离子酥料饼,类型错误:无法读取属性“秀”

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

是否允许popover正确返回?你的模板是否正确? – tpsilva

+0

@tpsilva你能解释更多关于承诺吗?我应该如何检查popver是否正确?该模板是正确的(由官方文档提供的模板) –

+0

但是,你有源文件夹中的模板? – tpsilva

回答

1

Fiddle与预期的行为。

<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”的模板。

0

最有可能这里的问题是,popover.html文件在子文件夹中保存的地方像“模板”或相似,指的是HTML文件还没有一个完整的限定路径分别脚本只是没有找到控制器文件popover.html。