Angularjs ionic-将ID添加到弹出窗口

Angularjs ionic-将ID添加到弹出窗口,angularjs,ionic-framework,ionic-popup,Angularjs,Ionic Framework,Ionic Popup,我想向ionic popup添加一个ID,但显然不可能使用框架提供的默认选项 由于它将使我的测试方法更容易使用ID,我试图添加它自己,但没有运气 基本上,我拥有的是一个创建我所有弹出窗口的服务(在下面的代码中,为了简单起见,我只添加一个): 服务: angular.module('modalsService', []).service('modals', [ '$ionicPopup', '$q', '$ionicSlideBoxDelegate', function($ionicPopup

我想向ionic popup添加一个ID,但显然不可能使用框架提供的默认选项

由于它将使我的测试方法更容易使用ID,我试图添加它自己,但没有运气

基本上,我拥有的是一个创建我所有弹出窗口的服务(在下面的代码中,为了简单起见,我只添加一个):

服务:

angular.module('modalsService', []).service('modals', [
  '$ionicPopup', '$q', '$ionicSlideBoxDelegate', function($ionicPopup, $q, $ionicSlideBoxDelegate) {
    var modals;
    modals = this;
    modals.deferred = null;
    modals.confirm = function(obj, $scope) {
      modals.deferred = $q.defer();
      $ionicPopup.show({
        title: "Are you sure?",
        scope: $scope,
        cssClass: 'confirmation-modal ' + obj.modalClass,
        template: obj.modalMessage,
        buttons: [
          {
            text: "Not Now",
            type: 'button-outline button-positive secondary',
            onTap: function() {
              if (modals.deferred != null) {
                return modals.deferred.resolve(false);
              }
            }
          }, {
            text: obj.confirmText,
            type: 'button-outline button-positive main',
            onTap: function() {
              if (modals.deferred != null) {
                return modals.deferred.resolve(true);
              }
            }
          }
        ]
      });
      return modals.deferred.promise;
    };
    return modals;
  }
]);
到目前为止非常简单,一个简单的服务,返回弹出窗口作为承诺,在我的控制器中,我这样称呼它:

$scope.evtClick = function() {
  var test;
  test = {
    modalClass: "modal-test",
    modalMessage: 'Do you really want to ... ?',
    confirmText: 'Test'
  };
  return hgModals.confirm(test, $scope).then(function(res) {
    if (res === true) {
      return console.log("Clicked the confirm button");
    } else {
      return console.log("Clicked the cancel button");
    }
  });
};
我在函数中传递的第一个参数是一个对象,它具有我需要打开的模态的特定选项

我也想在该对象中添加ID,但在创建承诺之前,我不知道如何将其添加到弹出窗口中,因此当我解析承诺时,ID已经添加到创建弹出窗口的最终代码中

类似这样的(服务):


创建一个自定义模式弹出窗口并将id标记附加到它上。您能说得更具体一点吗?对于
$ionic.popup.show(…)
模板
属性,您可以使用带有
离子内容
的html。因此基本上它将使用templateURL,将我的obj.message传递到模板中,并在ion内容中添加obj.id中的我的id标签,对吗?@Nick:你能发布最终答案吗?我也对解决方案感兴趣。
angular.module('modalsService', []).service('modals', [
  '$ionicPopup', '$q', '$ionicSlideBoxDelegate', function($ionicPopup, $q, $ionicSlideBoxDelegate) {
    var modals;
    modals = this;
    modals.deferred = null;
    modals.confirm = function(obj, $scope) {
      modals.deferred = $q.defer();
      var myConfirmModal = $ionicPopup.show({ //this is different from before
        title: "Are you sure?",
        scope: $scope,
        cssClass: 'confirmation-modal ' + obj.modalClass,
        template: obj.modalMessage,
        buttons: [
          {
            text: "Not Now",
            type: 'button-outline button-positive secondary',
            onTap: function() {
              if (modals.deferred != null) {
                return modals.deferred.resolve(false);
              }
            }
          }, {
            text: obj.confirmText,
            type: 'button-outline button-positive main',
            onTap: function() {
              if (modals.deferred != null) {
                return modals.deferred.resolve(true);
              }
            }
          }
        ]
      });
      myConfirmModal... //add ID here maybe? using obj.ID
      return modals.deferred.promise;
    };
    return modals; // the returning modal has already the ID applied
  }
]);