2017-06-16 57 views
1

爲我的離子v1應用程序我需要添加一個標題菜單(如引導菜單)在右上角。當我點擊這個按鈕時,我需要用相同的ng-click事件顯示菜單。對於圖形要求,我需要一個菜單​​,並沒有側面菜單。 找到$ ionicPopover,我認爲這是我的解決方案。 我的問題是關於菜單功能。我的想法是使用所有菜單的html模板,並將popover功能與所有應用程序的accessibile放在同一個位置。可能嗎? 僅找到一個例子,我需要實現popover功能的每個控制器。 例如,這是一個簡單的控制器。我需要爲我的所有項目全局定義popover函數。 popover定義相同。有可能嗎?謝謝。

.controller('DashCtrl', function($scope, $ionicLoading, $ionicPopover) { 
    // .fromTemplate() method 
    var template = '<ion-popover-view>' + '<ion-header-bar>' + 
     '<h1 class = "title">Popover Title</h1>' + 
     '</ion-header-bar>'+ '<ion-content>' + 
     'Popover Content!' + '</ion-content>' + '</ion-popover-view>'; 

    $scope.popover = $ionicPopover.fromTemplate(template, { 
     scope: $scope 
    }); 

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

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

    //Cleanup the popover when we're done with it! 
    $scope.$on('$destroy', function() { 
     $scope.popover.remove(); 
    }); 

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

    // Execute action on remove popover 
    $scope.$on('popover.removed', function() { 
     // Execute action 
    }); 
}) 
+0

對於每個頁面,你有一個單一的視圖模板嗎?通常你會有某種根模板來包裝你的所有UI路由器視圖。這個根模板將是這樣一個彈出菜單的適當的地方。 – Schlangguru

+0

頁面有不同的佈局。我需要添加一個共同的標題爲所有,並把它放在它的菜單。謝謝 –

回答

0

最後,我在單個控制器中創建了單一功能,並帶有一個通用菜單頭。謝謝。

0

就像在我的評論說,你應該創建保存所有視圖共享的邏輯獨立的控制器根模板視圖。看看下面的設置爲例:

「根模板」:(包含菜單按鈕)

<!-- templates/root.html --> 
<div> 
    <ion-nav-bar class="bar-positive"> 
     <ion-nav-buttons side="right"> 
      <button class="button icon ion-android-more-vertical" ng-click="showMenu($event)"></button> 
     </ion-nav-buttons> 
    </ion-nav-bar> 

    <ion-nav-view name="content"></ion-nav-view> 
</div> 

短跑模板:

<!-- views/dash.html --> 
<ion-view view-title="Dash View"> 
    <ion-content> 
     Hello World! 
    </ion-content> 
</ion-view> 

的狀態:

$stateProvider 
    .state('root', { 
     url: '/root', 
     abstract: true, 
     templateUrl: 'templates/root.html', 
     controller: 'RootCtrl' 
    }) 

    .state('root.dash', { 
     url: '/sub', 
     views: { 
      'content': { 
       controller: 'DashCtrl', 
       templateUrl: 'views/dash.html' 
      } 
     } 
    }) 

DashCtrl中,您將把邏輯放在彈出窗口中。因此該控制器必須執行showMenu($event)功能。

如果你真的需要爲你的酥料餅的模板,你可以在無論是在模板/ root.html或** RootController.js的代碼的HTML定義模板」。

+0

是的。現在我擁有了。但我需要的是實現showMenu($ event)功能的單點。在這種情況下,如果我有3個控制器,我需要爲單個控制器實現此功能。謝謝。 –