angular - 创建了新组件,但我在模块中收到有关提供程序的错误
问题描述
我创建了一个组件来发出警报,之后我收到了这个错误,关于该组件的某个提供程序。我不知道该怎么做才能修复它。
错误:
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 {
}
我需要添加什么?谁能帮我?它说了一些关于提供者的信息,但是什么提供者呢?
..................................................... …………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………………………………………………………… ..................................................... .....................
解决方案
您需要在 Module 的声明中添加 DiscountAllertComponent
推荐阅读
- loops - 在 Ansible 中的字典之间复制数据
- c# - 如何在 xamarin.android 中发送 PUT 请求?
- mysql - ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) 是否保留订单?
- javascript - 手风琴保存打开的卡并在回发后打开它
- flutter - Flutter 应用程序是否支持使用 microsoft intune 的 sso?
- javascript - 键是 ID 的对象的 PropType
- sql - 我们可以在 SQL 中使用 Insert 和 When Matched Then Merge 命令吗
- node.js - 节点 js 应用程序与 azure iot 连接以发送数据之间的经过时间
- reactjs - 如何使用 react-i18next Trans 组件编写默认翻译,即使用插值变量时有效的 JSX?
- vue.js - 带有本地存储密码的问题路由器