我收到错误" $ ionicPopover.fromTemplateUrl不是函数"用离子创造一个弹出窗口?

时间:2016-06-15 06:17:00

标签: angularjs ionic-framework popover

我有一个弹出窗口,根据语法一切都很好,但是我收到了这个错误" $ ionicPopover.fromTemplateUrl不是一个函数" ,如何解决这个问题?

我的控制员:

$ionicPopover.fromTemplateUrl('templates/namespaceSettingPopover1.html', {
            scope: $scope,
          }).then(function(popover) {
            $scope.popover = popover;
        });

        $scope.openSettings = function($event) {
            $scope.popover.show($event);
        };

        $scope.closeSettings = function() {
            $scope.popover.hide();
        };

        // Execute action on hide popover
        $scope.$on('popover.hidden', function() {
        // Execute action
        });

HTML:

  <div class="ion-android-funnel" ng-click="openSettings($event)">
                            <img src="img/filter.png" class="filterImg" />
                        </div>

错误:

ionic.bundle.js:19532 TypeError: $ionicPopover.fromTemplateUrl is not a function
    at new <anonymous> (CreatorTrackerController.js:46)
    at invoke (ionic.bundle.js:12110)
    at Object.instantiate (ionic.bundle.js:12118)
    at ionic.bundle.js:16387
    at self.appendViewElement (ionic.bundle.js:47357)
    at Object.render (ionic.bundle.js:45614)
    at Object.init (ionic.bundle.js:45534)
    at self.render (ionic.bundle.js:47231)
    at self.register (ionic.bundle.js:47189)
    at updateView (ionic.bundle.js:52439)

1 个答案:

答案 0 :(得分:0)

首先,您还需要显示控制器定义,例如控制器名称和您使用的依赖项。检查错误日志,并假设您的控制器 CreatorTrackerController ,当您未将 $ionicPopover 服务注入控制器时,会发生错误。请尝试以下方法。

 .controller('CreatorTrackerController', function($scope, $ionicPopover) {

    $ionicPopover.fromTemplateUrl('templates/namespaceSettingPopover1.html', {
                scope: $scope,
              }).then(function(popover) {
                $scope.popover = popover;
            });

            $scope.openSettings = function($event) {
                $scope.popover.show($event);
            };

            $scope.closeSettings = function() {
                $scope.popover.hide();
            };

            // Execute action on hide popover
            $scope.$on('popover.hidden', function() {
            // Execute action
            });

    });