【问题标题】:ionic 2 Redirect to another page if condition true from html pageionic 2 如果来自html页面的条件为真,则重定向到另一个页面
【发布时间】:2016-12-30 18:40:08
【问题描述】:

我需要在 ionic 2 中从我的 html 页面重定向另一个页面,
让我告诉我本地机器上的系统设置 -

******************************************************
Your system information:

Cordova CLI: 6.4.0 
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.1.8
Ionic App Lib Version: 2.1.4
ios-deploy version: Not installed
ios-sim version: 5.0.8 
OS: OS X Yosemite
Node Version: v6.2.2
Xcode version: Xcode 7.2 Build version 7C68
******************************************************

当一些 html 页面被编译时,在 html 的一些代码行之后重定向它。我知道怎么redirect from controller

if(1 > 2){
  this.rootpage = AuthTab;
}else{
  this.rootpage = AppTab;
}

但是现在我需要在某些条件为真时从 html 页面获取重定向,比如这样-

 <div *ngIf="((condition=='true')&& !(condition =='true'))">
   <div class="myclass">
      <div class="myclass">
         <div class="myclass">
            <div class="myclass">
               <div class="myclass">
                  <div class="myclass">
                     <div class="myclass" (click)="somePage($event, param1, param2)"> 
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>

因为我有点击重定向,但我想在没有点击的情况下做同样的事情

(<div class="myclass" (click)="somePage($event, param1, param2)"> )

mypage.ts 文件视为

somepage(event, param1,param2) {
    this.navCtrl.push(ViewPage, {
      Prm  : param1, 
      Prm2 : param2
    });
  }

上面的ts文件不用担心变量声明,我已经做到了。

也看过这个网址列表:-

  1. Ionic 2 : popToRoot() doesn't redirect to root component ( home page )
  2. https://github.com/driftyco/ionic/issues/5484

希望得到帮助!

【问题讨论】:

  • 那行
    是某个组件的一部分吗?
  • 这是用于检查条件的html标签,在page.html中有
  • 你能解释一下你想要完成什么吗?如果什么条件为真,你想在什么时候重定向用户?
  • 是的,如果条件为真,我想重定向到其他页面。
  • 那么为什么要签入您的模板?条件什么时候变成真似的?

标签: angular typescript ionic2


【解决方案1】:

为什么不使用“Eventemitter”

在 ts 中编写一个事件函数并编写另一个函数来监视您的条件并在条件为真时调用此事件函数 所以在这里你实际上是在调用 event.notify 自己当条件变为真时

捕捉你使用另一个函数触发的事件,你实际上从一个页面移动到另一个页面

EventEmitter 非常有用 只是阅读它 它可以有多种使用方式

【讨论】:

  • 我可以,但我处于这样一种情况,甚至可以在没有任何点击或类似的情况下发生。
猜你喜欢
相关资源
最近更新 更多
热门标签