I’m new to Ionic, I’m using v4, I’m new to Angular and I’m new to Typescript too, so please bear with me and forgive me if I make dumb questions. I’m on Linux.
I’ve started a new app with
$ ionic start
[...]
Project name: comptest
Framework: Angular
Starter template: tabs
[...]
First things first, I try it:
$ cd comptest
$ ionic serve -l
[...]
? Install @ionic/lab? Yes
[...]
the browser opens up and the app works ok. Now I try to generate a new custom component:
$ ionic generate component mySpan1
[...]
[OK] Generated component!
That created some files such as my-span1-component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-my-span1',
templateUrl: './my-span1.component.html',
styleUrls: ['./my-span1.component.scss'],
})
export class MySpan1Component {
constructor() { }
}
I edited the selector and made it look like my-span1
instead of app-my-span1
, but I didn’t touch anything else, not even the html <p>
tag that in future will become a <span>
instead for obvious reasons. Then I tried to use my-span1 in tab1 page, so I edit tab1.page.html and add my-span1 tag:
<ion-content>
<my-span1></my-span1>
<ion-card class="welcome-card">
<img src="/assets/shapes.svg" alt="" />
Now tab1 doesn’t work anymore. In the browser console I get the error:
‘my-span1’ is not a known element
Google is my friend, and it leads me here: Can’t get ionic v4 CLI generated component to work
I’ve tried to follow the suggestions in that thread, but when it came down to creating a new module I entered the unknown (for me) territory. I tried ionic generate module components
, and it worked, then I declared MySpan1Component in that new module:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MySpan1Component } from '../my-span1/my-span1.component';
@NgModule({
declarations: [
MySpan1Component
],
imports: [
CommonModule,
]
})
export class ComponentsModule { }
Then I imported the new module into the app module, like this:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ComponentsModule } from './components/components.module';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, ComponentsModule],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
But I still get the same error in the console, e.g. 'my-span1' is not a known element
.
There the thread ends, its author solved the problem with that, but the same is not true for me. And I don’t know what to do next.
Can you please guide me step by step (assuming I’m missing only 1 step or so), or hand me a link to some docs that guide me step by step?
Thanks in advance.