Hi, I have login screen and chat home screen. If user is logged in I need to show chat home screen otherwise I need to show chat Home screen after login .
So below is the my app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { TetraApp } from './app.component';
import { HttpModule } from '@angular/http';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { MenuProvider } from '../providers/menu/menu';
import { CategoryService} from './app.service';
import { RouterModule, Routes } from '@angular/router';
import { FormsModule} from '@angular/forms';
import {LoginService} from '../pages/login/login.service';
// import {CarouselModule} from "angular2-carousel";
import {chatHomePage} from '../pages/tetrachatHome/chatHome'
import {ChatService} from '../pages/tetrachatHome/chatHomeService';
import { LoginPage } from '../pages/login/login';
import {chatHistoryPage} from '../pages/chatHistory/chatHistoryCompo'
import {ChatHistoryService} from '../pages/chatHistory/chatHistoryService';
import {ExpandableComponent} from '../pages/expand/expandable.component';
import { FCM } from '@ionic-native/fcm/ngx';
import { Network } from '@ionic-native/network/ngx';
import { networkPage } from '../pages/network/networkcompo';
//import { BackgroundMode } from '@ionic-native/background-mode/ngx';
// import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
//import { Input } from '@ionic/angular';
const appRoutes: Routes = [
// { path: 'chat', component: chatHomePage},
// { path: 'login', component: LoginPage},
{ path: 'chatHistory/:id', component: chatHistoryPage},
{ path: 'network', component: networkPage}
];
@NgModule({
declarations: [
TetraApp,
chatHomePage,
networkPage,
// LoginPage,
chatHistoryPage,ExpandableComponent
],
imports: [
BrowserModule, RouterModule.forRoot(appRoutes),
IonicModule.forRoot(TetraApp),
HttpClientModule,FormsModule,HttpModule
//,CarouselModule
],
bootstrap: [IonicApp],
entryComponents: [
TetraApp,
chatHomePage,
networkPage
],
providers: [
StatusBar,
SplashScreen, HttpClient,
MenuProvider, CategoryService,LoginService,ChatService,ChatHistoryService,FCM,
Network,
// BackgroundMode,
//LocalNotifications,
{ provide: ErrorHandler, useClass: IonicErrorHandler }
]
})
export class AppModule { }
this is app.component.ts
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, MenuController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { MenuProvider } from '../providers/menu/menu';
import { CategoryService } from './app.service';
import { chatHomePage } from '../pages/tetrachatHome/chatHome';
import { LoginPage } from '../pages/login/login';
import { LoginService } from '../pages/login/login.service';
import { ExpandableComponent } from '../pages/expand/expandable.component';
import { Network } from '@ionic-native/network/ngx';
//import { BackgroundMode } from '@ionic-native/background-mode/ngx';
//import { LocalNotifications } from '@ionic-native/local-notifications/ngx';ionic cordova plugin add de.appplant.cordova.plugin.local-notification
import { FCM } from '@ionic-native/fcm/ngx';
import { networkPage } from '../pages/network/networkcompo';
//import { FCM } from '@ionic-native/fcm/ngx';
//import { RouterModule, Routes } from '@angular/router';
@Component({
selector: 'ion-app',
templateUrl: 'app.html'
})
export class TetraApp {
@ViewChild(Nav) nav: Nav;
chatHome = chatHomePage;
login1 = LoginPage;
networkScreen = networkPage;
pages: any;
public rootPage;
//TODO: remove coments
// rootPage: any = 'LoginPage';
//status regarding notification receive
notificationAlreadyReceived = false;
constructor(public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
public menuProvider: MenuProvider,
public menuCtrl: MenuController,
public loginService: LoginService,
private fcm: FCM,
private network: Network,
// public backgroundMode: BackgroundMode,//to make application available on background for any evnets
// public localNotifications: LocalNotifications//to generate local notifications
) {
this.isUserLoggedIn();
// this.initializeApp();
//subscribe to topic
this.fcm.subscribeToTopic('topic');
//printing fcm token when received
this.fcm.getToken().then(token => {
console.log("fcm token is " + token);
});
//executing when platform is ready
platform.ready().then(() => {
this.getNetworkConnectivityInfo();
this.trigger_backgroundEvents();
statusBar.styleDefault();
splashScreen.hide();
});
}
//based on user login status display login screen or home page.
isUserLoggedIn() {
//TODO:remove these comments for testing am hardcoding subbareddya@sathguru.come for user variable
var user = this.loginService.getUser();
//var user="subbareddya@sathguru.com";
if(user.length>0){
debugger;
this.rootPage= 'chatHomePage';
console.debug(" user is " + user + " user.length " + user.length);
//this.nav.push(this.rootPage);
}
else{
debugger;
console.debug(" new user login " );
this.rootPage = 'LoginPage';
}
}
//responding for background events
trigger_backgroundEvents() {
// this.backgroundMode.on('activate').subscribe(() => {
// console.log('activated');
// if(this.notificationAlreadyReceived === false) {
// this.showNotification();
// }
// });
// this.backgroundMode.enable();
}
//checking network for ondisconnect and onconnect
getNetworkConnectivityInfo() {
// watch network for a disconnection
this.network.onDisconnect().subscribe(() => {
console.log('network was disconnected :-(');
this.nav.push(this.networkScreen);
}, error => console.error(error));
// stop disconnect watch
//disconnectSubscription.unsubscribe();
// watch network for a connection
this.network.onConnect().subscribe(() => {
//debugger;
console.log('network connected!');
this.nav.pop();
// We just got a connection but we need to wait briefly
// before we determine the connection type. Might need to wait.
// prior to doing any api requests as well.
setTimeout(() => {
if (this.network.type === 'wifi') {
console.log('we got a wifi connection, woohoo!');
}
}, 3000);
}, error => console.error("online error " + error));
// stop connect watch
//connectSubscription.unsubscribe();
}
showNotification() {
// this.localNotifications.schedule({
// text: 'You have new message from tetra'
// });
// this.notificationAlreadyReceived = true;
}
// initializeApp() {
// this.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.
// // this.getSideMenuData();
// // this.getCat();
// this.statusBar.styleDefault();
// this.splashScreen.hide();
// this.getNetworkConnectivityInfo();
// });
// }
home() {
this.nav.push(this.rootPage);
}
refresh() {
this.nav.push(this.chatHome);
}
}
my login.ts is
import { Component,OnInit } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { LoginService } from './login.service';
import { chatHomePage } from '../tetrachatHome/chatHome';
/**
* Generated class for the HomePage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-home',
templateUrl:'login.html',
})
export class LoginPage {
rootPage: any = 'Topic1Page';
banners: any;
jsonData: any;
chatHme_Page=chatHomePage;
constructor(public navCtrl: NavController, public navParams: NavParams,
public LoginService:LoginService) {
}
signIn(id,un,pwd){
this.LoginService.getCredentials(id,un,pwd).subscribe(response => {
//this.banners =response.getbannerdataResult.BANNERLIST;
this.jsonData=response;
console.log("responce is "+JSON.stringify(response));
var result=response.response;
if(result=="success"){
this.LoginService.setIp(response.tetra_IP);
this.LoginService.setPort(response.tetra_PORT);
this.LoginService.setUser(response.Email);
this.LoginService.setIncludeUsers(response.users);
// this.navCtrl.setRoot(this.chatHme_Page);
this.navCtrl.push(this.chatHme_Page);
}
else{
alert(result);
console.log("result is not success "+JSON.stringify(response));
// alert(result);
}
}
,
(error) => console.log(error));
}
}
It is giving below errors. if I didnt comment the chatHomePage in app.module.ts.
core.js:15724 ERROR Error: Uncaught (in promise): Error: Type chatHomePage is part of the declarations of 2 modules: AppModule and ChatHomePageModule! Please consider moving chatHomePage to a higher module that imports AppModule and ChatHomePageModule. You can also create a new NgModule that exports and includes chatHomePage then import that NgModule in AppModule and ChatHomePageModule.
If I commented the chatHOmePAge in app.module.ts and if user is existed then it is allowing to chat home screen,
with the same If user is not logged in then whenever try to login and after it not allowing to go chat home screen it is giving below error
ERROR Error: Uncaught (in promise): Error: No component factory found for chatHomePage. Did you add it to @NgModule.entryComponents?.
So please help me out. Thanks in advance