«ионный заголовок» не является известным элементом ioni c 5 - PullRequest
1 голос
/ 21 февраля 2020

Ниже приведены шаги, которые я предпринял

  1. Я создал новый проект ioni c 5, используя ioni c start template blank
  2. обновленный angular до angular 9
  3. создал новый модуль страницы, используя ng g page main
  4. , указанный в AppRoutingModule с использованием отложенной загрузки.

Я получаю следующую ошибку

ERROR in src/app/pages/main/main.page.html:1:1 - error NG8001: 'ion-header' is not a known element:
1. If 'ion-header' is an Angular component, then verify that it is part of this module.
2. If 'ion-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

1 <ion-header>
  ~~~~~~~~~~~~

  src/app/pages/main/main.page.ts:5:16
    5   templateUrl: './main.page.html',
                     ~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component MainPage.
src/app/pages/main/main.page.html:2:3 - error NG8001: 'ion-toolbar' is not a known element:
1. If 'ion-toolbar' is an Angular component, then verify that it is part of this module.
2. If 'ion-toolbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress
this message.

2   <ion-toolbar>
    ~~~~~~~~~~~~~

  src/app/pages/main/main.page.ts:5:16
    5   templateUrl: './main.page.html',
                     ~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component MainPage.
src/app/pages/main/main.page.html:3:5 - error NG8001: 'ion-title' is not a known element:
1. If 'ion-title' is an Angular component, then verify that it is part of this module.
2. If 'ion-title' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

3     <ion-title>main</ion-title>
      ~~~~~~~~~~~

  src/app/pages/main/main.page.ts:5:16
    5   templateUrl: './main.page.html',
                     ~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component MainPage.
src/app/pages/main/main.page.html:7:1 - error NG8001: 'ion-content' is not a known element:
1. If 'ion-content' is an Angular component, then verify that it is part of this module.
2. If 'ion-content' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress
this message.

7 <ion-content>
  ~~~~~~~~~~~~~

Я упускаю что-то очень очевидное.

Ниже приведен код

app.module.ts

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 { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, BrowserAnimationsModule],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

app-routing.module.ts

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  {
    path: '',
    loadChildren: () => import('./pages/main/main-routing.module').then(m => m.MainPageRoutingModule)
  },
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

main.module. ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

import { IonicModule } from '@ionic/angular';

import { MainPageRoutingModule } from './main-routing.module';

import { MainPage } from './main.page';

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    MainPageRoutingModule
  ],
  declarations: [MainPage]
})
export class MainPageModule {}

main.page.ts

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

@Component({
  selector: 'sxm-main',
  templateUrl: './main.page.html',
  styleUrls: ['./main.page.scss'],
})
export class MainPage implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

main.page. html

<ion-header>
  <ion-toolbar>
    <ion-title>main</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>

</ion-content>

Ответы [ 2 ]

0 голосов
/ 10 апреля 2020

В моем случае я допустил глупую ошибку.

Импорт файла компонента, несмотря на необходимость импорта модуля в модуль маршрутизатора, вызвал ошибку.

0 голосов
/ 08 марта 2020

1-) Удалите папку node_modules и удалите блокировку пакета . json файл,

2-) Обновите глобальный angular -cli до последней версии,

3-) Убедитесь, что версия TypeScript не превышает версию, поддерживаемую Angular (менее 3.8.0),

4-) Выполнить npm установить на проекте и попробуйте снова!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...