GVKun编程网logo

如何在Ionic 3项目中使用angular 4路由器?(angular路由配置)

20

本文将分享如何在Ionic3项目中使用angular4路由器?的详细内容,并且还将对angular路由配置进行详尽解释,此外,我们还将为大家带来关于Angular4路由器和模态对话框、angular–

本文将分享如何在Ionic 3项目中使用angular 4路由器?的详细内容,并且还将对angular路由配置进行详尽解释,此外,我们还将为大家带来关于Angular 4路由器和模态对话框、angular – Ionic2:如何在每个子视图中使用不同的离子菜单、angular – 在Ionic 2中使用数组进行警报、angular – 如何在Ionic 2中隐藏带有标签的导航栏?的相关知识,希望对你有所帮助。

本文目录一览:

如何在Ionic 3项目中使用angular 4路由器?(angular路由配置)

如何在Ionic 3项目中使用angular 4路由器?(angular路由配置)

我正在开发一个混合应用程序.使用离子导航路由器,它很容易在页面之间导航,但它不使用浏览器的“URL路径”.

我看到我们可以在ionicModule上指定我们的链接.每次在某处导航时都可以使用它来指定关联的路径,离子将在浏览器中更改它.但是,使用它,如果您刷新浏览器,应用程序将丢失,您必须返回主页.

我认为可以简单地使用角度路由器,但是如何使用离子3?

谢谢

解决方法

首先,您在评论中引用了离子原生v3.然而,离子 – 天然和离子不是一回事.当您提出问题时,Ionic v3尚未正式发布,因此除非您使用测试版,否则我认为您仍然使用v2.

URL路径不需要角度路由器.在Ionic v2中,您可以这样做:

app.module.ts

export const deepLinkConfig: DeepLinkConfig = {
  links: [
    { component: Home,name: "home",segment: ""},{ component: DetailPage,name: "detail",segment: "event/:id",defaultHistory: [Home] }
  ]
};

然后将其包含在您的导入中:

IonicModule.forRoot(MyApp,{},deepLinkConfig)

您现在可以访问https://example.com/或https://example.com/event/1来访问应用页面.重新加载网站时,defaultHistory参数确保您仍然具有导航栏以导航回上一页.

在离子v3中,您可以使用IonicPage注释来配置路由:https://ionicframework.com/docs/nightly/api/navigation/IonicPage/

Angular 4路由器和模态对话框

Angular 4路由器和模态对话框

我有使用Angular路由器的Angular 4 SPA应用程序.
我想要使​​用Bootstrap 4在新对话框中打开组件的超链接.我已经知道如何从函数中打开模态对话框.

但是如何使用超链接打开它?

<a [routerLink]="['/login']">Login</a>

我想留下我当前的组件,只是在它前面显示模态对话框.

另一个问题 – 是否有可能以编程方式执行此操作?这样我就可以

this.router.navigate(['/login']);

并在当前组件上显示登录模式对话框?

有什么建议?

我最好的猜测是你可能想要订阅激活的路线并改变路线中的参数以触发模态.
import { ActivatedRoute,Params } from '@angular/router';
import { Component,OnInit } from '@angular/core';

@Component({
  selector: 'cmp1',templateUrl: './cmp1.component.html',styleUrls: ['./cmp1.component.css'],})
export class Cmp1 implements OnInit {

    constructor(private activatedRoute: ActivatedRoute) {
    }

    ngOnInit() {
        this.activatedRoute.params.subscribe(params => {
            if (params["modal"] == 'true') {
                // Launch Modal here
            }
        });
    }
}

我相信你会有一个看起来像这样的链接:
< a [routerLink] =“['/ yourroute',{modal:'true'}]”>

可以在这里找到更好的例子:Route Blog

angular – Ionic2:如何在每个子视图中使用不同的离子菜单

angular – Ionic2:如何在每个子视图中使用不同的离子菜单

我正在尝试学习Ionic2侧面菜单的使用,并希望看看我是否可以在每个子视图中都有一个单独的侧面菜单.

我安装了一个入门应用程序,它在主应用程序中有一个离子菜单,即在我们的bootstrap app.html文件中

<ion-menu [content]="content">

 <ion-toolbar>
   <ion-title>Pages</ion-title>
 </ion-toolbar>

 <ion-content>
   <ion-list>
     <button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
       {{p.title}}
     </button>
   </ion-list>
  </ion-content>

</ion-menu>

<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>

然后我添加了自己的页面,并在示例应用程序的初始根页面getting-started.ts中添加以下内容以导航到我的新页面.

public goToSideMenuPage(): void{    
   this._navController.push(SideMenuPage);

我还添加了一个按钮来调用上面的处理程序.

在SideMenuPage中,我希望它拥有自己完全不同的侧面菜单.我试过以下……

<ion-menu [content]="thecontent">
<ion-toolbar>
  <ion-title>Menu title</ion-title>
</ion-toolbar>

<ion-content>
 <ion-list>
    <button>button1</button>
    <button>button2</button>
 </ion-list>
 </ion-content>
</ion-menu>

<ion-content #thecontent>
  <div>Main contents text</div>
 </ion-content>

但是,当我转到我的页面时,我看到的只是左上角的主要内容文本.我没有看到菜单汉堡包图标,如果我向右拖动,我会看到应用程序主菜单在app.html中设置,而不是我自己的“本地”菜单,内容为

<button>button1</button>
<button>button2</button>

在doco发现here时,该演示确实显示了在运行时交换的侧边菜单,但我无法在任何地方看到它的实际代码.这接近我想要做的事情(虽然我希望它根据我导航到的子页面进行交换),所以看起来确实可能这样做,但我只是不明白我应该怎么做这样做.

有谁知道这是否可能,如果是的话,怎么做?

您正在寻找的信息位于Ionic2文档的 MenuController部分.这可以通过添加app.html中的菜单来完成,但是为它们分配如下ID:
<ion-menu [content]="content" side="left" id="menu1">
  <ion-toolbar secondary>
    <ion-title>Menu 1</ion-title>
  </ion-toolbar>
  <ion-content>
    <ion-list>
      <button ion-item menuClose="menu1" detail-none>
        Close Menu 1
      </button>
    </ion-list>
  </ion-content>
</ion-menu>

<ion-menu [content]="content" side="right" id="menu2">
  <ion-toolbar danger>
    <ion-title>Menu 2</ion-title>
  </ion-toolbar>
  <ion-content>
    <ion-list>
      <button ion-item menuClose="menu2" detail-none>
        Close Menu 2
      </button>
    </ion-list>
  </ion-content>
</ion-menu>

<ion-nav [root]="rootPage" #content></ion-nav>

然后,在每个页面中,我们可以决定应该激活哪个菜单,如下所示:

constructor(private menu: MenuController,private nav: NavController) { }

  ionViewDidEnter() {
    // Use the id to enable/disable the menus
    this.menu.enable(true,'menu1');
    this.menu.enable(false,'menu2');
  }

另外,请注意我使用this.nav.setRoot(Page1)显示第二页;而不是使用像this.nav.push(Page1);.

编辑:如果您希望两个菜单同时处于活动状态,请查看this answer.

编辑2:就像@peterc在评论中所说:

I found this also worked if I had my side menu in my page
sidemenu-page.html and set this.menu.enable(true,‘menu1’); in it’s
component (so there is the option to have the side menu with the
markup of the page that will switch to it
).

我将其添加到答案中,因为将要使用它的视图似乎是放置菜单而不是app.html的更好位置.

angular – 在Ionic 2中使用数组进行警报

angular – 在Ionic 2中使用数组进行警报

如何使用数组填充警报列表.例如,如果数组有一堆名称.

array = [john,dixy,tom,jared];

我希望弹出警报并显示这些名称,以便从中进行选择.
我正在使用离子2.

解决方法

由于通过使用带有选项的对象创建警报,我们可以使用该对象创建具有数组名称的单选按钮.

import { Component } from "@angular/core";
import { AlertController } from "ionic-angular/index";

@Component({
  templateUrl:"home.html"
})
export class HomePage {

  private names: Array<string>;

  constructor(private alertCtrl: AlertController) { 
    this.names = [ 'john','dixy','tom','jared']; 
  }

  presentConfirm() {

    // Object with options used to create the alert
    var options = {
      title: 'Choose the name',message: 'Which name do you like?',buttons: [
        {
          text: 'Cancel',role: 'cancel',handler: () => {
            console.log('Cancel clicked');
          }
        },{
          text: 'Ok',handler: data => {
            console.log(data);
          }
        }
      ]
    };

    options.inputs = [];

    // Now we add the radio buttons
    for(let i=0; i< this.names.length; i++) {
      options.inputs.push({ name : 'options',value: this.names[i],label: this.names[i],type: 'radio' });
    }

    // Create the alert with the options
    let alert = this.alertCtrl.create(options);
    alert.present();
  }
}

希望这可以帮助 :)

angular – 如何在Ionic 2中隐藏带有标签的导航栏?

angular – 如何在Ionic 2中隐藏带有标签的导航栏?

如何在Ionic 2中隐藏带有标签的导航栏?

我只想将其隐藏在其中一个页面中,而不包括其他页面.

<ion-navbar *navbar   >
  <ion-title>Item Details</ion-title>
</ion-navbar>

我试过hide-nav-bar =“true”但它不起作用.

解决方法

从标签页中您可以执行以下操作:

this.nav.parent.parent.setRoot(LoginPage);

之前:

导航 – >标签 – > SomePage的

后:

导航 – > LoginPage

Nav is the root of all nav stacks in Ionic 2

此外,模式适用于您希望在新视图中显示列表项的详细信息但没有导航选项卡或导航栏占用宝贵屏幕空间的情况.

目前我认为除了使用CSS之外,还有一种方法可以在选项卡页面的子视图上隐藏选项卡.如果您决定使用CSS选项,那么我建议使用Angular的ngClass属性https://angular.io/docs/ts/latest/api/common/index/NgClass-directive.html设置一个类,而不是隐藏导航标签或导航栏.

今天关于如何在Ionic 3项目中使用angular 4路由器?angular路由配置的分享就到这里,希望大家有所收获,若想了解更多关于Angular 4路由器和模态对话框、angular – Ionic2:如何在每个子视图中使用不同的离子菜单、angular – 在Ionic 2中使用数组进行警报、angular – 如何在Ionic 2中隐藏带有标签的导航栏?等相关知识,可以在本站进行查询。

本文标签: