关闭离子弹出

时间:2015-12-23 14:43:54

标签: ionic-framework ionic popover

我有一个popover模板,如:

void printBoard(char board[N][N]) {
    for (int i = N-1; i >= 0; i--) {
        printf("%d %c ", i, BAR);
        for (int j = 0; j < N; j++) {
            printf("%c ", board[i][j]);
        }
        printf("\n");
    }
    for (int l = 0; l < 2; l++) {
        for(int k = -4; k < N; k++) {
            if(k < 0) {
                printf("%c", SPACE);
            }
            else {
               if(l == 0) {
                    printf("%c ", EMDASH);
                }
                else {
                    printf("%d ", k);
                }
            }
        }
            printf("\n");
    }
}

在控制器中我有

<ion-popover-view class="fit">
  <ion-content scroll="false">
    <ion-list>
      <ion-item ng-click="popoverGotoView(foo, {id: 1})">
        Option 1
      </ion-item>
      <ion-item ng-click="popoverGotoView(foo, {id: 2})">
        Option 2
      </ion-item>
    </ion-list>
  </ion-content>
</ion-popover-view>

其中$ scope.popover是基于离子文档得到的。 Popover显示,点击它会转到另一个视图,但它不会隐藏。我试图调试它去隐藏方法,但内部,离子正在改变弹出类,而在DOM中没有效果。单击外部弹出窗口,它可以正常隐藏。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

这是一段代码段。问题在哪里?

angular.module('ionicApp', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('tabs', {
      url: "/tab",
      abstract: true,
      templateUrl: "templates/tabs.html"
    })
    .state('tabs.home', {
      url: "/home",
      views: {
        'home-tab': {
          templateUrl: "templates/home.html",
          controller: 'HomeCtrl'
        }
      }
    })
    .state('tabs.map', {
      url: "/map",
      views: {
        'map-tab': {
          templateUrl: "templates/map.html",
          controller: 'MapCtrl'
        }
      }
    });

   $urlRouterProvider.otherwise("/tab/home");

})

.run(function($rootScope) {

})

.controller('HomeCtrl', function($scope, $state, $ionicPopover) {
  console.log('HomeCtrl');
    $ionicPopover.fromTemplateUrl('templates/popover.html', {
      scope: $scope,
    }).then(function(popover) {
      $scope.popover = popover;
    });
  
  $scope.popoverGotoView = function(path, arg) {
    $scope.popover.hide();
    $state.go(path, arg);
  }
  
})

.controller('MapCtrl', function($scope, $state, $ionicPopover) {
  console.log('MapCtrl');
    $ionicPopover.fromTemplateUrl('templates/popover.html', {
      scope: $scope,
    }).then(function(popover) {
      $scope.popover = popover;
    });
  
  $scope.popoverGotoView = function(path, arg) {
    $scope.popover.hide();
    $state.go(path, arg);
  }

});
<html ng-app="ionicApp">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  <title>Tabs Example</title>
  <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
  <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>

<body>

  <ion-nav-bar class="bar-positive">
    <ion-nav-back-button>
    </ion-nav-back-button>
  </ion-nav-bar>

  <ion-nav-view></ion-nav-view>

  <script id="templates/tabs.html" type="text/ng-template">
    <ion-tabs class="tabs-icon-top tabs-positive">

      <ion-tab title="Home" icon="ion-home" href="#/tab/home">
        <ion-nav-view name="home-tab"></ion-nav-view>
      </ion-tab>

      <ion-tab title="Map" icon="ion-ios-world" ui-sref="tabs.map">
        <ion-nav-view name="map-tab"></ion-nav-view>
      </ion-tab>

    </ion-tabs>
  </script>

  <script id="templates/home.html" type="text/ng-template">
    <ion-view view-title="Home">
      <ion-nav-buttons side="right">
        <button class="button button-icon ion-more" ng-click="popover.show($event)"></button>
      </ion-nav-buttons>
      <ion-content class="padding">
        Home view
        <p>
          <a class="button icon icon-right ion-chevron-right" href="#/tab/map">Go to Map</a>
        </p>
      </ion-content>
    </ion-view>
  </script>

  <script id="templates/map.html" type="text/ng-template">
    <ion-view title="">
      <ion-nav-buttons side="left">
        <input id="places" class="controls" type="text" autocomplete placeholder="Enter a location" />
      </ion-nav-buttons>
      <ion-nav-buttons side="right">
        <button class="button button-icon ion-more" ng-click="popover.show($event)"></button>
      </ion-nav-buttons>

      <ion-content>
        Map view
      </ion-content>

    </ion-view>
  </script>

    <script id="templates/popover.html" type="text/ng-template">
    <ion-popover-view class="fit">
      <ion-content scroll="false">
        <ion-list>
          <ion-item ng-click="popoverGotoView('tabs.map', {id: 1})">
            Option 1 Map
          </ion-item>
          <ion-item ng-click="popoverGotoView('tabs.home', {id: 2})">
            Option 2 Home
          </ion-item>
        </ion-list>
      </ion-content>
    </ion-popover-view>
  </script>
  
</body>

</html>