1
votes

I am creating a page in Ionic and I have also created a separate component for the footer and I am using the footer selector in my page but It is showing the error.

This is my components>foot-card>foot-card.ts

import { Component } from '@angular/core';

@Component({
  selector: 'foot-card',
  templateUrl: 'foot-card.html'
})
export class FootCardComponent {

  text: string;

  constructor() {
    console.log('Hello FootCardComponent Component');
    this.text = 'Hello World';
  }

}

This is my components.module.ts:

import { NgModule } from '@angular/core';
import { FootCardComponent } from './foot-card/foot-card';
import { IonicModule } from 'ionic-angular';

@NgModule({
    declarations: [FootCardComponent],
    imports: [IonicModule],
    exports: [FootCardComponent]
})

export class ComponentsModule {}

This is my app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { LoginpagePage } from '../pages/loginpage/loginpage';
import { FrontPage } from './../pages/front/front';
import { FooterPage } from './../pages/footer/footer';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { HttpClientModule } from '@angular/common/http';
import { RestapiProvider } from '../providers/restapi/restapi';
import { FootCardComponent } from '../components/foot-card/foot-card';
import { ComponentsModule } from '../components/components.module'


@NgModule({
  declarations: [
    MyApp,
    HomePage,
    ListPage,
    LoginpagePage,
    FrontPage,
    FooterPage,
    FootCardComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    ComponentsModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    ListPage,
    LoginpagePage,
    FrontPage,
    FooterPage,
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    RestapiProvider
  ]
})
export class AppModule {}

This is the selector that i am using in my front page: (front.html)

<foot-card></foot-card>

but it is showing the error . I am new to ionic. Any help is much appreciated.

Error:

Type FootCardComponent is part of the declarations of 2 modules: ComponentsModule and AppModule! Please consider moving FootCardComponent to a higher module that imports ComponentsModule and AppModule. You can also create a new NgModule that exports and includes FootCardComponent then import that NgModule in ComponentsModule and AppModule.

3
Your template is in this case footer.html.. are you sure this isnt empty?Jonathan
What is the error?Silvermind
Yes. my footer.html is not empty. @Jonathanuser8531037
So actually it seems you want to use a Ionic Page as Component. You should create a component instead of a Page: ionicframework.com/docs/cli/generateJonathan
btw: here is a nice tutorial for creating a component: joshmorony.com/build-a-custom-flash-card-component-in-ionic-2Jonathan

3 Answers

1
votes

Cut FootCardComponent from declarations and add it to Entry Components. and let me know is this working for you or not.

0
votes

Just, In the app.module.js: Remove FootCardComponent from declarations and add it to Entry Components. This solved my problem.

See Ionic 4 custom components

0
votes

Please follow the steps

Remove the FootCardComponent from the declaration part of app.module.ts file.

Add ComponentsModule in the import section of app.module.ts file.

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { LoginpagePage } from '../pages/loginpage/loginpage';
import { FrontPage } from './../pages/front/front';
import { FooterPage } from './../pages/footer/footer';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HttpClientModule } from '@angular/common/http';
import { RestapiProvider } from '../providers/restapi/restapi';
import { FootCardComponent } from '../components/foot-card/foot-card';
import { ComponentsModule } from '../components/components.module'


@NgModule({
  declarations: [
    MyApp,
    HomePage,
    ListPage,
    LoginpagePage,
    FrontPage,
    FooterPage,
    FootCardComponent **-------> *Remove this line***
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    ComponentsModule, ---------> *Add ComponentsModule in import section*
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    ListPage,
    LoginpagePage,
    FrontPage,
    FooterPage,
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    RestapiProvider
  ]
})
export class AppModule {}

Let me know your outcome