本文介绍了没有NavController的提供者!离子3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的大学项目使用 Ionic3
,我添加了 app.html
的设置部分,并尝试链接(click)="home()"
,但对我不起作用.
I'm Using Ionic3
for my university project , I had added setting parts of my app.html
and trying to link (click)="home()"
but it's not working for me.
我遇到以下错误
app.html
<!--------------------------------------Main Navigation--------------------------->
<ion-menu id="myMenu" [content]="content" side="right" persistent="true" [class]="selectedTheme">
<ion-header>
<ion-toolbar>
<ion-grid>
<ion-row>
<ion-col col-6>
<div text-left style="" class="app-listname">
Project</div>
</ion-col>
<ion-col (click)="home()">
<div class="tether-setting" style="text-align: right;font-size: 2rem; color:#a57958;">
<ion-icon ios="ios-settings-outline" md="md-settings"></ion-icon>
</div>
</ion-col>
<ion-col>
<div class="tether-logout" style="font-size: 2rem; color:#a57958; text-indent: 0rem; text-align: right;">
<ion-icon ios="ios-log-out" md="md-log-out"></ion-icon>
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-toolbar>
</ion-header>
<ion-content>
<div class="ion-tm">
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" [class.activeHighlight]="checkActive(p)" (click)="openPage(p)">
<ion-icon [name]="p.icon" item-left></ion-icon>{{p.title}}</button>
</ion-list>
</div>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" [class]="selectedTheme"></ion-nav>
<!--------------------------------------Main Navigation--------------------------->
app.component.ts
import {Component, ViewChild} from '@angular/core';
import {Nav, Platform,NavController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
import {HomePage} from '../pages/home/home';
import {SettingsPage} from "../pages/settings/settings";
import {HelpPage} from "../pages/help/help";
import {UserloginslidePage} from "../pages/userloginslide/userloginslide";
import {SettingsProvider} from "../providers/settings/settings";
import {ModalPage} from "../pages/modal/modal";
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = UserloginPage;
selectedTheme: String; //Themeoption
activepage: any;
pages: Array<{ title: string, component: any, icon: string }>;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
this.settings.getActiveTheme().subscribe(val => this.selectedTheme = val); //Themeoption
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
this.pages = [
{title: 'Dashboard', component: HomePage, icon: "ios-home-outline"},
{title: 'Settings', component: SettingsPage, icon: "ios-settings-outline"},
{title: 'Help', component: HelpPage, icon: "ios-help-circle-outline"},
{title: ' User loginslide ', component:UserloginslidePage, icon: "ios-contact-outline"},
];
this.activepage = this.pages[0];
}
//Themeoption
openPage(page) {
this.nav.setRoot(page.component);
this.activepage = page;
}
checkActive(page) {
return page == this.activepage;
}
home(){
this.navCtrl.push(HomePage);
}
}
推荐答案
那么,为什么要尝试导入NavController?您有 @ViewChild(Nav)导航:Nav;
可以使用它.
Well, why do you try to import NavController? You have @ViewChild(Nav) nav: Nav;
you can use it.
您必须将 NavController 从注入构造函数中移除
You must remove NavController from injecting in your constructor
替换您的行
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
与
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider) {
然后替换行
this.navCtrl.push(HomePage);
与
this.nav.push(HomePage);
这篇关于没有NavController的提供者!离子3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!