1
我在我的angular 2.0.0应用程序中安装了ng2-toasty:“^ 2.3.0”。在angular2中ng2-toasty不起作用
我包括在应用模块,这些线
import { ToastyModule } from 'ng2-toasty';
@NgModule({
imports: [
UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.
ToastyModule.forRoot()
],
而在我的TS文件我有这样的代码
import { ToastyService, ToastyConfig, ToastOptions, ToastData } from 'ng2-toasty';
constructor(private toastyService: ToastyService, private toastyConfig: ToastyConfig) {
this.toastyConfig.theme = 'default';
}
onClick() {
debugger;
this.toastyService.default({
title: "Toast It!",
msg: "Mmmm, tasties...",
showClose: true,
timeout: 5000,
theme: "default"
});
// Or create the instance of ToastOptions
var toastOptions: ToastOptions = {
title: "My title",
msg: "The message",
showClose: true,
timeout: 5000,
theme: 'default',
onAdd: (toast: ToastData) => {
console.log('Toast ' + toast.id + ' has been added!');
},
onRemove: function (toast: ToastData) {
console.log('Toast ' + toast.id + ' has been removed!');
}
};
// Add see all possible types in one shot
this.toastyService.info(toastOptions);
this.toastyService.success(toastOptions);
this.toastyService.wait(toastOptions);
this.toastyService.error(toastOptions);
this.toastyService.warning(toastOptions);
}
和HTML我有
<button (click)="onClick()">Click</button>
<ng2-toasty></ng2-toasty>
我能得到消息,但它不是作为通知,它只是作为纯文本消息。你能不能让我错过什么。
。 – code1
我的标题 消息 我的标题 消息 我的标题 消息 我的标题 消息 我的标题 消息 – code1