如何解决现在创建了一个简单的组件,但出现有关提供程序的错误
做这个项目,我创建了一个简单的组件来放置我的广告,现在我遇到了这个错误,我无法解决:
StaticInjectorError(AppModule)[discountAllertComponent]: StaticInjectorError(平台:核心)[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 {
}
解决方法
为页面创建组件时,必须在正在使用的页面的声明中的.module.ts文件中声明它:[]。例如
declarations: [DiscountAllertComponent]
如果仍然无法使用,请尝试将其添加到:
entryComponents: [DiscountAllertComponent]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。