如何使用离子弹出中的条件

时间:2022-11-16 23:01:08

i created one common Popup screen its used in three module but three module have different title. I didn't give if condition in title, Is possible or not anybody give solution to me.

我创建了一个常用的Popup屏幕,它在三个模块中使用但三个模块有不同的标题。我没有给出标题中的条件,是否有可能给我解决方案。

popup code here :

弹出代码在这里:

function showPopup () {
  $scope.data = {};
  var myPopup = $ionicPopup.show({
    template: '<input focus-me type="text" ng-model="data.expensetype" limit-char limit="15">',
    if (vm.usertype === 'Worker') {
      title: $translate.instant('{{"wtype_message" | translate}}'),
    }
    else if (vm.usertype === 'Buyer') {
      title: $translate.instant('{{"btype_message" | translate}}'),
    }
    else if (vm.usertype === 'Expense') {
      title: $translate.instant('{{"etype_message" | translate}}'),
    }
    scope: $scope,
    buttons: [
     { text: $translate.instant('{{"pcancel_message" | translate}}') },
      {
        text: $translate.instant('{{"psave_message" | translate}}'),
        type: 'button-positive',
        onTap: function (e) {
          if (!$scope.data.expensetype) {
            e.preventDefault();
          } else {
            addExpenseCategory();
            return $scope.data.expensetype;
          }
        }
      },
    ]
  });
  myPopup.then(function (res) {
    $log.log('Tapped!', res);
  });
}

1 个解决方案

#1


1  

Try this:

尝试这个:

var categorytitle = '';
  $log.log('vm.usertype', vm.usertype);
  switch (vm.usertype) {
    case 'Farmer':
      categorytitle = 'Enter coconut type';
      break;
    case 'Worker':
      categorytitle = $translate.instant('{{"venterworktype_message" | translate}}');
      break;
    case 'Buyer':
      categorytitle = $translate.instant('{{"venterproduct_message" | translate}}');
      break;
    case 'Group':
      categorytitle = $translate.instant('{{"wtype_message" | translate}}');
      break;
    case 'Expense':
      categorytitle = $translate.instant('{{"newexpensetype_message" | translate}}');
      break;
  }
  var myPopup = $ionicPopup.show({
    template: '<input focus-me type="text" ng-model="data.expensetype" limit-char limit="15">',
    //title: $translate.instant('{{"penterexpensetype_message" | translate}}'),
    title: categorytitle,
    scope: $scope,
    buttons: [
     { text: $translate.instant('{{"pcancel_message" | translate}}') },
      {
        text: $translate.instant('{{"psave_message" | translate}}'),
        type: 'button-positive',
        onTap: function (e) {
          if (!$scope.data.expensetype) {
            //don't allow the user to close unless he enters producttype
            e.preventDefault();

          } else {
            addExpenseCategory();
            return $scope.data.expensetype;
          }
        }
      },
    ]
  });
  myPopup.then(function (res) {
    $log.log('Tapped!', res);
  });

#1


1  

Try this:

尝试这个:

var categorytitle = '';
  $log.log('vm.usertype', vm.usertype);
  switch (vm.usertype) {
    case 'Farmer':
      categorytitle = 'Enter coconut type';
      break;
    case 'Worker':
      categorytitle = $translate.instant('{{"venterworktype_message" | translate}}');
      break;
    case 'Buyer':
      categorytitle = $translate.instant('{{"venterproduct_message" | translate}}');
      break;
    case 'Group':
      categorytitle = $translate.instant('{{"wtype_message" | translate}}');
      break;
    case 'Expense':
      categorytitle = $translate.instant('{{"newexpensetype_message" | translate}}');
      break;
  }
  var myPopup = $ionicPopup.show({
    template: '<input focus-me type="text" ng-model="data.expensetype" limit-char limit="15">',
    //title: $translate.instant('{{"penterexpensetype_message" | translate}}'),
    title: categorytitle,
    scope: $scope,
    buttons: [
     { text: $translate.instant('{{"pcancel_message" | translate}}') },
      {
        text: $translate.instant('{{"psave_message" | translate}}'),
        type: 'button-positive',
        onTap: function (e) {
          if (!$scope.data.expensetype) {
            //don't allow the user to close unless he enters producttype
            e.preventDefault();

          } else {
            addExpenseCategory();
            return $scope.data.expensetype;
          }
        }
      },
    ]
  });
  myPopup.then(function (res) {
    $log.log('Tapped!', res);
  });