2016-12-06 105 views
3

目前,我正在开发一个使用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 上搜索了文档,但找不到处理事件的解决方案,当用户点击弹出窗口时,您能否给我建议一些建议?

非常感谢。

+0

试<烤面包机容器(点击)= “内容()”> anshuVersatile

回答

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); 
    } 
} 

实时演示:http://plnkr.co/edit/uL98EbfIBd6pm7bMU80V?p=preview

+0

非常感谢! –

+0

Yw!看到我的更新..照顾关闭按钮。 – mxii

+0

谢谢,我认为我们需要返回一个布尔值的clickHandler函数,作为ClickHandler的接口: export interface ClickHandler {tolash:Toast,isCloseButton?:boolean):boolean; } –

1

doc,你有onShowCallback

var toast: Toast = { 
    type: 'success', 
    title: 'parent', 
    onShowCallback: (toast) => { 
    // stuff here 
    } 
}; 

this.toasterService.pop(toast); 
+0

谢谢Soywod! –