首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular2-toaster自定义类

angular2-toaster自定义类
EN

Stack Overflow用户
提问于 2019-01-31 22:22:07
回答 1查看 626关注 0票数 0

我们在我们的项目中使用了angular2-toaster,我遇到了一个问题,那就是我不能向toaster实例添加自定义类。

我的烤面包机配置看起来很棒,我想要传递带有烤面包机自定义类的customClass数组。

代码语言:javascript
复制
showToaster(msg: string, customClass: string | string[]) {
   const toast: Toast = {
     type: customClass[0],
     body: msg
   };

   this.toasterService.pop(toast);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-31 23:25:48

您可以使用ToasterConfig,然后将其绑定到您的toaster-container

代码语言:javascript
复制
@Component({
  selector: 'my-app',
  template: `
    <div>
      <toaster-container [toasterconfig]="config"></toaster-container>
      <button (click)="popToast()">pop toast</button><br/>
    </div>
  `,
})
export class App {

  public config : ToasterConfig = new ToasterConfig({
    typeClasses: {
      class1: 'custom-class-1',
      class2: 'custom-class-2',
      class3: 'custom-class-3'
      /* goes on */
    }
  });

   /*
   other stuff of component 
   */
}

然后你就可以像你发布的那样使用它:

代码语言:javascript
复制
showToaster(msg: string, customClass: string | string[]) {
   const toast: Toast = {
     type: customClass[0], // class1 or class2 or class3 or etc
     body: msg
   };

   this.toasterService.pop(toast);
}

参考文献:

https://github.com/Stabzs/Angular2-Toaster/issues/110

https://github.com/Stabzs/Angular2-Toaster/blob/master/src/toaster-config.ts

http://plnkr.co/edit/gZTxVXD8lN3fibqhDYod?p=preview

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54462628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档