2014-10-31 195 views
6

如何默認顯示ionicPopover,請勿點擊或任何其他事件。一旦頁面或視圖加載,顯示彈出?默認情況下如何顯示ionicPopover

cmr.controller('JoinMeeting', function($scope, $ionicPopover) { 
    $ionicPopover.fromTemplateUrl('joinMrTips.html', { 
    scope: $scope, 
}).then(function(popover) { 
    $scope.popover = popover; 
}); 

$scope.$on('$viewContentLoaded',function(){ 
    $scope.popover.show(); 
}); 

}) 

回答

9

你非常接近。據IonicPopover的官方文檔,popover.show()的語法如下:

show($event) where The $event or target element which the popover should align itself next to

因此,重寫代碼如下將做的工作:

$scope.$on('$viewContentLoaded',function(){ 
    $scope.popover.show(".class-of-host-control-of-popup"); 
}); 

完整的例子,沿使用代碼 - >here

+0

是的,它的工作,非常感謝 – user3117414 2014-11-06 03:13:09

+0

很高興它幫助@ user3117414。請接受我的答覆作爲答案。 – 2014-11-06 03:38:20

+0

悲哀:未捕獲錯誤:[jqLit​​e:nosel] jqLit​​e不支持通過選擇器查找元素!請參閱:http://docs.angularjs.org/api/angular.element – 2015-04-22 10:17:11

2

這工作不必包括jQuery的:

$scope.$on('$viewContentLoaded',function(){ 
    $scope.popover.show(angular.element(document.querySelector('.class-of-host-control-of-popup'))); 
}); 
1

的,它使用離子「utils的」類(在這裏,DomUtil)爲例:

var nodeClass = 'target-host-item-class'; 
    var evtTarget = $event.target; 
    var hostNode = ionic.DomUtil.getParentOrSelfWithClass(evtTarget, nodeClass); 

    $ionicPopover.fromTemplateUrl('popover-template.html', { 
     scope: $scope 
    }).then(function(popover) { 
     popover.show(hostNode); 
    }); 

不是真的惡化或比其他更好的答案。簡單地避免使用直接DOM查詢或jQuery。

在這裏,我希望彈出窗口始終與使用類.target-host-item-class的項目對齊。

相關問題