离子调用的3弹出窗口之一取决于一些变数 [英] Ionic calling one of 3 popups depending on some variable

查看:90
本文介绍了离子调用的3弹出窗口之一取决于一些变数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个弹出我的应用程序离子;

  angular.module('启动器')
  .controller('PopupCtrl',函数($范围,$ ionicPopup,$超时){
    $ scope.showAlert1 =功能(){
      VAR alertPopup = $ ionicPopup.alert({
        标题:更迭!,
      });
    };
    $ scope.showAlert2 =功能(){
      VAR alertPopup = $ ionicPopup.alert({
        标题:失败......,
      });
    };
    $ scope.showAlert3 =功能(){
      VAR alertPopup = $ ionicPopup.alert({
        标题:第三选项,
      });
    };
  });

我想它们分配到一个按钮。当按钮被点击以及

VAR X = 1 我想打电话 showAlert1

VAR X = 2 我想打电话 showAlert2

VAR X = 3 我想打电话 showAlert3

这可能吗?

编辑:

我的index.html的结构:

 <机身NG-应用=启动器NG-控制器=PopupCtrl>  <离子导航栏类=扎阳对齐标题=中心>
  < /离子导航栏>  <离子导航视图类=滑 - 左 - 右>< /离子NAV-视图>  <脚本ID =list.html类型=文/ NG-模板>
    <离子视图标题=MyApp的>
      <离子NAV-按键侧=右>
        <按钮类=按钮按钮图标图标离子Android的定位NG点击=showAlert()的onclick =WRITETEXT()>< /按钮>
      < /离子NAV-按钮>      <离子含量>
        < UL类=清单>
            <! - 一些列表 - >
        < / UL>
      < /离子含量>
    < /离子视图>    <! - 一些子页面的模板 - >< /身体GT;


所以

解决方案

你的所有警报都只是标题相同(或模板,如果你使用该选项),而不是单独调用$ ionicPopup.alert()调用功能只是让一个函数来调用,并把条件对标题和模板像这样

  $ scope.showAlert =功能(){
      变种myTitle =;
      如果(X == 1){
        标题=更迭!;
     }否则如果(X == 2){
        标题=失败!;
     }其他{标题=第三种方案; }
      VAR alertPopup = $ ionicPopup.alert({
        标题:myTitle
      });
  };

I have 3 popups in my Ionic app;

angular.module('starter')
  .controller('PopupCtrl', function($scope, $ionicPopup, $timeout) {
    $scope.showAlert1 = function() {
      var alertPopup = $ionicPopup.alert({
        title: 'Succes!',
      });
    };
    $scope.showAlert2 = function() {
      var alertPopup = $ionicPopup.alert({
        title: 'Fail...',
      });
    };
    $scope.showAlert3 = function() {
      var alertPopup = $ionicPopup.alert({
        title: 'Third option',
      });
    };
  });

I'd like to assign them to one button. When the button is clicked and

var x=1 i'd like to call showAlert1

var x=2 i'd like to call showAlert2

var x=3 i'd like to call showAlert3

Is it possible?

EDIT:

My index.html structure:

<body ng-app="starter" ng-controller="PopupCtrl">

  <ion-nav-bar class="bar-positive" align-title="center">
  </ion-nav-bar>

  <ion-nav-view class="slide-left-right"></ion-nav-view>

  <script id="list.html" type="text/ng-template">
    <ion-view title="MyApp">
      <ion-nav-buttons side="right">
        <button class="button button-icon icon ion-android-locate" ng-click="showAlert()" onclick="writeText()"></button>
      </ion-nav-buttons>

      <ion-content>
        <ul class="list">
            <!--some list-->
        </ul>
      </ion-content>
    </ion-view>

    <!--some subpages templates-->

</body>

解决方案

All of your alerts are same except title (or template, if you are using that option), so instead of calling $ionicPopup.alert() call in separate functions just make one function to call that, and put condition on title and template like this

 $scope.showAlert = function() {
      var myTitle = "";
      if(x==1){
        title = "Succes!";
     } else if(x==2){ 
        title = "Fail!"; 
     } else { title = "third option"; }
      var alertPopup = $ionicPopup.alert({
        title: myTitle
      });
  };

这篇关于离子调用的3弹出窗口之一取决于一些变数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆