我尝试构建ionic 4应用程序。但是,在尝试修复前一个错误之后,新错误仍然出现。 在发生此错误之后,我已经创建了一个自定义组件(How to load other page inside of an ionic segment?) 然后我得到一个错误:addchilds组件是2个模块的声明的一部分。我查找该错误,并创建了shared.module.ts并将其导入app.module.ts中。但是我仍然遇到错误,这次是
Uncaught Error: Template parse errors:
‘ion-col’ is not a known element:
1. If 'ion-col' is an Angular component, then verify that it is part of this module.
2. If 'ion-col' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
<div>
<ion-row no-padding>
[ERROR ->]<ion-col size="6" offset="3">
<img [src]="image" alt="this is the image"/>
</io"): ng:///SharedModule/AddchildsComponent.html@3:10
不幸的是,该错误也发生在离子行,离子按钮,离子输入上。这是最近的代码。
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { FormsModule } from '@angular/forms';
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 firebaseConfig from './firebase';
*/
import { ImagePicker } from '@ionic-native/image-picker/ngx';
import { WebView } from '@ionic-native/ionic-webview/ngx';
import { AngularFireModule } from '@angular/fire';
import { environment } from '../environments/environment';
import { AngularFirestoreModule, FirestoreSettingsToken } from '@angular/fire/firestore';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { IonicSelectableModule } from 'ionic-selectable';
import { CommonModule } from '@angular/common';
import { SharedModule } from './shared/shared.module';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
AngularFireModule.initializeApp(environment. firebase),
AngularFirestoreModule,
AngularFireAuthModule,
IonicSelectableModule,
FormsModule,
CommonModule,
SharedModule
],
providers: [
StatusBar,
SplashScreen,
ImagePicker,
WebView,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{ provide: FirestoreSettingsToken, useValue: {} }
],
bootstrap: [AppComponent]
})
export class AppModule {}
app-routing.modules.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AddchildsComponent } from '../app/pages/addchilds/addchilds.component';
const routes: Routes = [
{ path: 'login', loadChildren: './login/login.module#LoginPageModule' },
{ path: 'register', loadChildren: './register/register.module#RegisterPageModule' },
{ path: '', redirectTo: 'register', pathMatch: 'full' },
{ path: '', loadChildren: './pages/tabs/tabs.module#TabsPageModule' },
{ path: 'childdetails/:id', loadChildren: './pages/childdetails/childdetails.module#ChilddetailsPageModule' },
{ path: 'adddetails/:id', component: AddchildsComponent },
{ path: 'services', loadChildren: './services/services.module#ServicesPageModule' },
];
@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [RouterModule]
})
export class AppRoutingModule { }
shared.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AddchildsComponent } from '../pages/addchilds/addchilds.component';
@NgModule({
declarations: [ AddchildsComponent ],
imports: [ CommonModule ],
exports: [ AddchildsComponent ]
})
export class SharedModule { }
我真的不知道该怎么解决,有人可以帮我吗?让我知道您是否需要其他代码。
答案 0 :(得分:3)
您必须将其添加到共享模块中而不是在addchils中为我工作
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { HeaderPage } from '../header/header.page';
@NgModule({
declarations: [HeaderPage],
exports: [HeaderPage],
imports: [
IonicModule,
CommonModule
]
})
export class SharedModule { }
答案 1 :(得分:0)
Ionic 4现在正在使用Web组件,这意味着对于所有使用ion- *之类的组件,您需要在此类component.ts文件中显式导入Ionic Module。请将下面的导入添加到您的addchils.module.ts中:
import { IonicModule } from '@ionic/angular';