navCtrl ionic 3无效链接

时间:2018-12-11 07:49:39

标签: javascript ionic-framework ionic3

我正在为离子应用程序尝试navegate,但我不知道为什么链接不起作用。任何想法?该应用程序是在Ionic 3中开发的

错误“未捕获(承诺);无效链接:首页

  

help.html

<ion-content>
  <ion-slides>
          <ion-slide>
            <div class="box blue">
                <img src="assets/imgs/x.png" (click)="goToHome()" />
            </div>
          </ion-slide>
    </ion-slides>
</ion-content>
  

help.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HelpPage } from './help';

@NgModule({
  declarations: [
    HelpPage
  ],
  imports: [
    IonicPageModule.forChild('HelpPage')
  ],
  entryComponents: [
    HelpPage
  ],
  exports: [
    HelpPage
  ]
})
export class HelpPageModule {}
  

help.ts

import {Component, ViewChild, ElementRef, NgModule} from '@angular/core';
import {IonicPage, IonicPageModule, Platform, Slides, NavController} from 'ionic-angular';

import { HomePage } from '../home/home';

@Component({
  selector: 'page-help',
  templateUrl: 'help.html'
})
export class HelpPage {
  @ViewChild(Slides) slides: Slides;

  constructor(private platform:Platform, public navCtrl: NavController){}

  goToHome(){
    this.navCtrl.push('HomePage');
  }
}

3 个答案:

答案 0 :(得分:0)

您在app.module.ts中添加了主页吗?

答案 1 :(得分:0)

您的主目录是否包含home.module.ts?看起来您需要通过在@Component之前声明@IonicPage()来声明“ HomePage”是一个IonicPage,类似

import { Component } from '@angular/core';
import { IonicPage } from 'ionic-angular';

@IonicPage()
@Component({
    selector: 'home-page',
    templateUrl: 'home-page.html',
})
export class HomePage {
//your HomePage logic goes here
    constructor(){}
}

然后,您将必须在“主”目录中创建 home-page.module.ts 文件

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';

@NgModule({
  declarations: [
    HomePage
  ],
  imports: [
    IonicPageModule.forChild(HomePage),
  ],
  exports: [
    HomePage
  ]
})
export class HomePageModule {}

重新加载项目,然后重试

答案 2 :(得分:0)

import { Component, ViewChild } from '@angular/core';
import { IonicPage,NavController}from 'ionic-angular';
import { ViewmapPage } from '../viewmap/viewmap';
@IonicPage({name: 'page-dash-board',
segment: 'my-dash-board'})
@Component({
  selector: 'page-dash-board',
  templateUrl: 'dash-board.html',
})
export class DashBoardPage {
 constructor(public navCtrl: NavController)
  {
    this.go();
  }
  go(){
  this.navCtrl.push(ViewmapPage);
  }
}