【发布时间】:2019-08-09 13:22:11
【问题描述】:
我想在某些操作后显示 toast 通知,但我想显示一个自定义 toast 组件。我已经创建并配置如下:
在我的app.module:
imports: [
ToastrModule.forRoot({
positionClass: "toast-top-left",
toastComponent: myCustomToastComponent
}),
]
entryComponents: [
myCustomToastComponent
]
然后我有我的自定义 component.ts:
import { Component, Input } from "@angular/core";
import { Toast, ToastrService, ToastPackage } from "ngx-toastr";
@Component({
selector: "app-ribbon",
templateUrl: "./ribbon.component.html",
styleUrls: ["./ribbon.component.scss"]
})
export class myCustomToastComponent extends Toast {
@Input() messageText: string;
constructor( protected toastrService: ToastrService, public toastPackage: ToastPackage) {
super(toastrService, toastPackage);
}
}
html:
<div class="custom-ribbon-container">
{{ messageText }}
</div>
还有css:
.custom-ribbon-container {
border-color: green;
-moz-border-radius: 15px;
border-radius: 15px;
width: 400px;
height: 30px;
}
我在另一个组件中调用toastr 服务:
showToaster() {
this.toastr.success("testing toast message", "title");
}
}
这是html:
<button (click)="showToaster()">
Show Toaster
</button>
这里的问题是它没有显示我的自定义 toast 组件,它显示了 toastr 包中的默认组件。并在控制台上显示此错误:“Found the synthetic property @flyInOut. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application." 我错过了什么?
Pd:我已经安装了 BrowserAnimations 并将其包含在 app.module 中
【问题讨论】:
标签: angular notifications angular7 toastr