标签:
在ionic中,modal也是添加控制器写服务的~
在modal.html页面中增加控制器:ng-controller="aboutCtrl"
记住要给这个添加控制器。
头部使其关闭按钮,只需要使用ng-click = "hide()"
在app.js中初始化modal:
$rootScope.aboutModal = modalSvc.createModal(‘templates/about.html‘);
在控制器下要使用:
$scope.openAboutModal = function(){
$rootScope.aboutModal.show();
}
modalSvc.js:
记住在最后要返回。
var modalSvc = angular.module(‘passbox.modalSvc‘, [‘ionic‘]);
modalSvc.factory(‘modalSvc‘, [
‘$rootScope‘, ‘$ionicModal‘
, function ($rootScope, $ionicModal) {
function createModal(templateURL) {
var modalService = {
scope: $rootScope.$new(),
modalWindow: undefined,
show: function (params) {
this.scope.params = params;
if (this.modalWindow) {
this.modalWindow.show();
}
},
hide: function () {
if (this.modalWindow) {
this.modalWindow.hide();
}
}
};
$ionicModal.fromTemplateUrl(templateURL, function (modal) {
modalService.modalWindow = modal;
}, {
scope: modalService.scope,
animation: ‘slide-in-up‘
});
modalService.scope.hide = function () {
modalService.hide();
};
return modalService;
}
return {createModal: createModal};
}
]);
标签:
原文地址:http://www.cnblogs.com/maoyazhi/p/4462845.html