我对离子非常陌生,而不是有角度的专业人士。我正在尝试为可以从控制器调用的弹出窗口创建服务。我正在使用一项服务,因为多个控制器可能需要使用弹出窗口,并且我可能需要不同类型的弹出窗口。我什至不确定这是正确的方法,请原谅我,但我正在尝试。我希望该服务将已单击哪个按钮(确定/取消)传递回控制器,以便可以添加或不添加案例。
非常感谢。
弹出服务
angular.module('services')
.service('popupService', function ($ionicPopup) {
return {
createCasePopup : function () {
$ionicPopup.show({
cssClass: 'custom-popup',
title: 'Create Case',
subTitle: 'Are you sure you want to create this case?',
buttons: [
{
text: 'Cancel',
onTap: function (e) {
return 'cancel button pressed';
}
},
{
text: 'Ok',
type: 'button-positive',
onTap: function (e) {
return 'ok button pressed';
}
},
]
}).then(
function (res) {
console.log(res);
},
function (err) {
console.log('Err:', err);
},
function (msg) {
console.log('message:', msg);
});
}
}
});
控制器
$scope.addCase = function () {
// this line to return which button has been clicked?
var createCase = popupService.createCasePopup();
if (createCase && $scope.case) {
caseService.add($scope.case);
}
};