2016-12-06 140 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! –

相關問題