单击Angular2-toaster弹出窗口时如何处理事件

时间:2016-12-06 07:15:38

标签: angular angular2-toaster

目前,我正在开发一个使用angular2-toaster的项目。

// Show message notification
  this.toasterService.pop('success',
    `New message from ${data.sender.name} (${data.sender.hid})`,
    data.message);

当用户点击弹出窗口时,我想显示对话框以获取更多详细信息。 我在https://www.npmjs.com/package/angular2-toaster上搜索了该文档 但是当用户点击弹出窗口时找不到处理事件的解决方案,你能给我一些建议吗?

非常感谢。

2 个答案:

答案 0 :(得分:3)

您可以使用clickHandler

@Component({
  selector: 'my-app',
  template: `
    <div>
      <toaster-container [toasterconfig]="config1"></toaster-container>
      <button (click)="popToast()">pop toast</button><br/>
    </div>
  `,
})
export class App {
  private toasterService: ToasterService;

  constructor(toasterService: ToasterService) {
    this.toasterService = toasterService;
  }

  popToast() {
    var toast: Toast = {
      type: 'info',
      title: 'Here is a Toast Title',
      body: 'Here is a Toast Body',
      showCloseButton: true,
      clickHandler: (t, isClosed): boolean => {
        console.log('i am clicked..', isClosed, t);

        // got clicked and it was NOT the close button!
        if (!isClosed) {

        }

        return true; // remove this toast !
      }
    };

    this.toasterService.pop(toast);
  }
}

live-demo:http://plnkr.co/edit/uL98EbfIBd6pm7bMU80V?p=preview

答案 1 :(得分:1)

doc开始,您拥有contradiction

onShowCallback