【发布时间】:2019-05-28 02:29:37
【问题描述】:
我目前正在使用 Angular 7 开发一个网络应用程序。我想包含 ngx-toastr 以向用户发送通知,但它没有按预期工作。当我触发吐司时,什么都没有发生,除了吐司大小的框出现在右下角,但只有当游标悬停时才会出现。 以下是我如何触发 toastr 函数的示例。通过单击按钮调用测试。
import {ToastrService} from 'ngx-toastr';
@Component({
selector: 'app-action-controls',
templateUrl: './action-controls.component.html',
styleUrls: ['./action-controls.component.scss']
})
export class Notification implements OnInit {
test(){
this.toast.success("I'm a toast!", "Success!");
}
constructor(private toast: ToastrService) { }
}
我在项目的 angular.json 文件中包含库 css 文件,如下所示:
...
"styles": [
"src/styles.scss",
"node_modules/bootstrap/scss/bootstrap.scss",
"node_modules/ngx-toastr/toastr.css"
],
...
在我的 app.module.ts 文件中就像这样:
...
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {ToastrModule} from 'ngx-toastr';
...
imports: [
...
BrowserAnimationsModule,
ToastrModule.forRoot({
timeOut: 1000,
positionClass: 'toast-bottom-right'
})
]
...
我不知道我做错了什么,有没有人有类似的经历?非常感谢!
【问题讨论】:
-
非常感谢您的回答,我已经走得更远了。现在 toast 已正确呈现,但仍仅在您将鼠标悬停在其上时才会显示。
-
这可能是因为您的自定义 css。如果有帮助,请为答案投票
-
我通过添加 @import '~ngx-toastr/toastr.css' 来修复它;进入 style.css