Posts

Showing posts with the label service

angular - call function from different typescript file

angular - call function from different typescript file I am facing issue whiling calling a function/method from another typescript file. I have read through many articles and found using service it can be done easily so here I am with my code but it is not working. It is not throwing any error but not giving any results too. trigger.html <button (click) = "openToast();" type="button" class="btn btn-primary btn-block"> Open Toast </button> trigger.ts import { Component, OnInit } from '@angular/core'; import { MessageService } from '../message.service'; @Component({ selector: 'app-trigger', templateUrl: './trigger.component.html', styleUrls: ['./trigger.component.scss'], providers: [MessageService] }) export class TriggerComponent implements OnInit { constructor(private _messageService: MessageService) { } ngOnInit() { } openToast(){ this._messageService.callToastr(); } } message.ser...