2017-05-04 62 views
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> 

我能得到消息,但它不是作为通知,它只是作为纯文本消息。你能不能让我错过什么。

+0

。 – code1

+0

我的标题 消息 我的标题 消息 我的标题 消息 我的标题 消息 我的标题 消息 – code1

回答

0

我有同样的问题。您需要从html中的模块导入.css文件之一。 我最终复制bootstrap.css到它自己的文件/assets/vendors/toasty-bootstrap.css(因为我不想引用我的ng_modules目录里面)。

有可能是我得到这样一个更好的方式来引用该组件内的文件,但

<link href="/assets/vendors/toasty-bootstrap.css" rel="stylesheet"> 

<button (click)="onClick()">Click</button> 
    <ng2-toasty></ng2-toasty>