首页 > 解决方案 > 创建了新组件,但我在模块中收到有关提供程序的错误

问题描述

我创建了一个组件来发出警报,之后我收到了这个错误,关于该组件的某个提供程序。我不知道该怎么做才能修复它。

错误:

custom-error-handler.ts:19 NullInjectorError: StaticInjectorError(AppModule)[DiscountAllertComponent]: 
  StaticInjectorError(Platform: core)[DiscountAllertComponent]: 
    NullInjectorError: No provider for 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() {}


  async createDiscountAlert(restaurantData,userData) {
    const alert = await this.alertController.create({
      cssClass: 'teste',
      header: restaurantData.promotion.type.discountTittle,
      message: restaurantData.promotion.type.discountDescription,
      buttons: [
        {
          text: 'Percebi!',
          handler: () => {
            console.log('Confirm Okay');
            console.log(userData);
            this.af.object("/user/" + userData.key + '/promotion').set({alertSeen: true});
          }
        }
      ]
    });

    await alert.present();
  }


}

组件模块:

    import {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 {
}

我需要添加什么?谁能帮我?它说了一些关于提供者的信息,但是什么提供者呢?

..................................................... …………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………………………………………………………… ..................................................... .....................

标签: angularionic-frameworkerror-handlingmodulecomponents

解决方案


您需要在 Module 的声明中添加 DiscountAllertComponent


推荐阅读