0

Problem

In an ionic app, i am using two custom angular components. In one of the angular component, i want to use two ionic components, <ion-icon> and <ion-fab> but ionic is throwing two errors

ion-icon is not a known element

and

ion-fab is not a known element

Question

How can i use ionic components inside custom angular components?

Here's the component which in which i am using ionic components

footer.html

<div class="footer-container">
  <div class="comics-option-container">
    <img class="comics-icon" src="../../assets/imgs/grid2.png" />
    <p>Comics</p>
  </div>

  <div class="search-option-container">
    <ion-fab class="search-fab-btn-container">
      <button ion-fab class="search-btn">
          <ion-icon name="ios-search" color="white"></ion-icon>
      </button>
    </ion-fab>

    <p>Search</p>
  </div>

  <div class="edit-option-container">
    <img class="posting-icon" src="../../assets/imgs/edit1.png" />
    <p>Posting</p>
  </div>
</div>

components.module.ts

import { NgModule } from '@angular/core';
import { HeaderComponent } from './header/header';
import { IonicModule } from 'ionic-angular';
import { FooterComponent } from './footer/footer';
import { CommonModule } from '@angular/common';
@NgModule({
    declarations: [HeaderComponent, FooterComponent],
    imports: [IonicModule],
    exports: [HeaderComponent, FooterComponent]
})
export class ComponentsModule {}

HeaderTestPage is the page in which i am using this component, below is its module file

headertest.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule, IonicModule } from 'ionic-angular';
import { HeaderComponent } from '../../components/header/header';
import { FooterComponent } from '../../components/footer/footer';
import { SharedModule } from '../../shared.module';
import { HeaderTestPage } from './headertest';

@NgModule({
  declarations: [
    HeaderTestPage
  ],
  imports: [
    IonicPageModule.forChild(HeaderTestPage),
    SharedModule
  ],
})

export class HeaderTestPageModule {}

1 Answer 1

1

I got the same problem as you had and I find the way to solving it and helping everybody else who have the same issue.

You need to import IonicModule and CommonModule in components.module.ts to solve the problem.

@NgModule({
 imports: [
  CommonModule,
  IonicModule
 ],
 ...
})

I finded the solution thanks to the comment of Wils on the thread "Ionic 3 can't use ion- components inside my custom components"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.