plauzul / ng2-izitoast

MIT License
19 stars 8 forks source link

iziToast as service #1

Closed JonathanRamier closed 6 years ago

JonathanRamier commented 7 years ago

Hello,

I try to use your angular component ng2-iziToast, but the use of component is very difficult. Why do you not implement a angular service this is my code

import { Injectable } from '@angular/core';

const iziToast = require('izitoast/dist/js/iziToast');
require('izitoast/dist/css/iziToast.min.css');

@Injectable()
export class ToasterService {

  private toasterConfig = {
    title: 'Title',
    titleColor: '',
    message: 'Message',
    messageColor: '',
    backgroundColor: '',
    color: '',
    icon: '',
    iconText: '',
    iconColor: '',
    image: '',
    imageWidth: 50,
    zindex: 99999,
    layout: 1,
    close: true,
    rtl: false,
    position: 'bottomRight',
    target: '',
    targetFirst: true,
    timeout: 5000,
    drag: true,
    pauseOnHover: true,
    resetOnHover: false,
    progressBar: true,
    progressBarColor: '',
    animateInside: true,
    buttons: {},
    transitionIn: 'fadeInUp',
    transitionOut: 'fadeOut',
    transitionInMobile: 'fadeInUp',
    transitionOutMobile: 'fadeOutDown'
  };

  public showToaster(config: any) {
    const iziToastConfig = Object.assign({}, this.toasterConfig, config);
    iziToast.show(iziToastConfig);
  }
}

then you call it

export class AppComponent implements OnInit {

  constructor(private toastSvc: ToasterService) { }

  ngOnInit() {
    this.toastSvc.showToaster({
      title: 'Bonjour',
      message: 'Bienvenue sur l\'extranet'
    });
  }
}
plauzul commented 7 years ago

Is a component, to be implemented only using html. A service already needs to use the controller which needs to be avoided. What problem did you get?

JonathanRamier commented 7 years ago

My trouble was I had Two modules which used two izitoaster, one for the notification, the other for validation of my request. I need to put the component iziToaster in the two modules. So how can I generate the message on component like notification or validation when my event fired if the ng-izitoaster ran already in html ?

plauzul commented 7 years ago

Ok the next version will be a service

Albejr commented 6 years ago

I need too.