Как узнать, на какой конкретный тостер нажимали? - PullRequest
0 голосов
/ 18 апреля 2019

Я успешно показал тост от ngx-toaster.Я показываю тостер для различных типов уведомлений по идентификатору и коду задачи.

Я пытался получить обратный вызов касания и обратный вызов действия, но ничего не нашел взамен.

onNotificationReceived(res) {
        let key;
            switch (key) {
                case 1:
                    showSuccessPopup(res.title,res.body);
                    break;

                default:
                    break;
            }
    }

showSuccessPopup(title,body) {
        this.toastr
            .success(title, body, { closeButton: true })
            .onTap.subscribe((action) => console.log(action))
    }

Фактический результат: Показан тост

Ожидается: для которого был показан тост id

1 Ответ

0 голосов
/ 18 апреля 2019

this.toastr.success() показывает уведомление тостера и возвращает ActiveToast -объект.И вы звоните onTap на этот конкретный тостер.Если вы хотите получить доступ к объекту toastr в подписке, сохраните его в переменной:

const toastr = this.toastr.success(/* ... */);
toastr.onTap.subscribe(action => /* use toastr here */);
/* you can also use toastr here */

toastr выглядит следующим образом:

export interface ActiveToast {
  /** Your Toast ID. Use this to close it individually */
  toastId: number;
  /** the message of your toast. Stored to prevent duplicates */
  message: string;
  /** a reference to the component see portal.ts */
  portal: ComponentRef<any>;
  /** a reference to your toast */
  toastRef: ToastRef<any>;
  /** triggered when toast is active */
  onShown: Observable<any>;
  /** triggered when toast is destroyed */
  onHidden: Observable<any>;
  /** triggered on toast click */
  onTap: Observable<any>;
  /** available for your use in custom toast */
  onAction: Observable<any>;
}

см. Документ: https://www.npmjs.com/package/ngx-toastr

...