i want to do global toasts service in my application with own styles and html for toasts. I'm using ng2-toastr. For example i have component A. In view i have button:
<button (click)="showSuccess()">Click</button>
in controller i have showSuccess function :
showSucess() {
this.toastrService.showSuccess({
enableHTML: true,
toastLife: 3000,
});
}
In my ToastrService i have my showSuccess function:
import { Injectable } from '@angular/core';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
@Injectable()
export class ToastrService {
constructor(public toastr: ToastsManager) {}
showSucess() {
this.toastr.custom('<span style="color: #bd362f">This message should be in red with blank background. Click to dismiss.</span>',
'Custom Message', {dismiss: 'click'});
}
}
this.toastr.custom - in this function i set my own toast template. Now, i want to do component with this template, because i want to remove this template from service.
How can i replace this string with HTML with component? I want to replace this string with innerHTML of component, or something like this. I want share in this component with toasts options from component from the top of my question.
In AngularJs i used $templateCache to get html from file, but in angular2 + i cann't find something like this.