scttcper / ngx-toastr

🍞 Angular Toastr
https://ngx-toastr.vercel.app
MIT License
2.51k stars 359 forks source link

toasts not removed from dom if extending service #843

Open JLNNN opened 4 years ago

JLNNN commented 4 years ago

Hey,

when I'm using class MyToastrService extends ToastrService { to "wrap" the ToastrService into my own, all the toast messages are still in dom after being dismissed. Is that an intended behaviour?

When using the original ToastrService, everything is working fine.

Thanks in advance, Julian

huyungtang commented 4 years ago

Hi,

You may check out if there are more than one instance of ToastrService in your application.

Here is my testing case in my application:

  1. Inject ToastrService & MyToastrService in one component.
  2. Use MyToastrService to active any toastr.
  3. Check the property "currentlyActive", it should be the same both in ToastrService & MyToastrService.

Hope this would help!

manzapanza commented 1 week ago

Hey, I solved the problem by injecting the NgxToastrService in my custom Service like so:

import { Injectable } from '@angular/core';
import {
  IndividualConfig,
  ToastrService as NgxToastrService,
} from 'ngx-toastr';
import { ResponseError } from '../types/response-error.type';

@Injectable({
  providedIn: 'root',
})
export class ToastrService {
  constructor(private ngxToastrService: NgxToastrService) {}

  success(
    message?: string,
    title?: string,
    options?: Partial<IndividualConfig<any>>,
  ) {
    this.ngxToastrService.success(message, title, options);
  }

  responseError(
    response: ResponseError,
    title?: string,
    options?: Partial<IndividualConfig<any>>,
  ) {
    ....
    ....
    ....
    return this.ngxToastrService.error(message, title, options);
  }
}