做这个项目,我创建了一个简单的组件来放置我的allert,现在我有这个错误,我不能解决:
StaticInjectorError(AppModule)DiscountAllertComponent: StaticInjectorError(Platform: core) DiscountAllertComponent : NullInjectorError:没有DiscountAllertComponent的提供者!
我像往常一样创建了组件,我不知道我必须做些什么来修复它!
组件:
import { Component, OnInit } from '@angular/core';
import {AngularFireDatabase} from '@angular/fire/database';
import {AlertController} from '@ionic/angular';
import {Router} from '@angular/router';
@Component({
selector: 'app-discount-allert',
templateUrl: './discount-allert.component.html',
styleUrls: ['./discount-allert.component.scss'],
})
export class DiscountAllertComponent implements OnInit {
constructor(
// public af: AngularFireDatabase,
public alertController: AlertController) { }
ngOnInit() {}
}组件模块:
mport {CUSTOM_ELEMENTS_SCHEMA, NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {SharedHeaderComponent} from './shared-header/shared-header.component';
import {AlertController, IonicModule} from '@ionic/angular';
import {UserInfoComponent} from './user-info/user-info.component';
import {AddressComponent} from './address/address.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {TranslateModule} from '@ngx-translate/core';
import {PasswordStrengthBarModule} from 'ng2-password-strength-bar';
import {SchedulerComponent} from './scheduler/scheduler.component';
import {OrderConfigurationComponent} from './order-configuration/order-configuration.component';
import {OrderComponent} from './order/order.component';
import {MenuComponent} from './menu/menu.component';
import {DishOptionsComponent} from './dish-options/dish-options.component';
import {PasswordResetComponent} from './password-reset/password-reset.component';
import {OrderResumeComponent} from './order-resume/order-resume.component';
import {PaymentMethodComponent} from './payment-method/payment-method.component';
import {OnlinePaymentComponent} from './online-payment/online-payment.component';
import {PipesModule} from '../pipes/pipes.module';
import {ChangePasswordComponent} from './change-password/change-password.component';
import {CardsManagerComponent} from './cards-manager/cards-manager.component';
import {LocationSelectComponent} from './location-select/location-select.component';
import {MbrefComponent} from './mbref/mbref.component';
import {MbwayComponent} from './mbway/mbway.component';
import {CardModule} from '../directives/card/module';
import {DiscountAllertComponent} from './discount-allert/discount-allert.component';
const COMPONENTS = [
AddressComponent,
CardsManagerComponent,
ChangePasswordComponent,
DishOptionsComponent,
LocationSelectComponent,
MbrefComponent,
MbwayComponent,
MenuComponent,
OrderComponent,
OrderConfigurationComponent,
OrderResumeComponent,
PasswordResetComponent,
SchedulerComponent,
SharedHeaderComponent,
UserInfoComponent,
PaymentMethodComponent,
OnlinePaymentComponent,
DiscountAllertComponent
];
@NgModule({
declarations: [COMPONENTS],
imports: [
IonicModule,
CardModule,
CommonModule,
FormsModule,
PasswordStrengthBarModule,
ReactiveFormsModule,
TranslateModule,
PipesModule,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
exports: [COMPONENTS],
entryComponents: [COMPONENTS],
})
export class ComponentsModule {
}发布于 2020-08-31 19:55:53
当您为页面创建组件时,您必须在所使用页面的声明:[]的.module.ts文件中声明它。例如:
declarations: [DiscountAllertComponent]如果仍然不起作用,请尝试将其添加到:
entryComponents: [DiscountAllertComponent]https://stackoverflow.com/questions/63667893
复制相似问题