Seeking advice on how to efficiently place a single instance of $mdToast (from Angular Material) into a base class (Typescript). In my UI, I have five tabs with separate controller instances and it seemed logical to centralize the $mdToast declaration in a base class rather than repeating it. However, despite having its own "$inject" property, it seems to be overridden by the one in the derived class. Any suggestions on the best approach for moving $mdToast to a common base class? Here is a snippet of my current code:
Note that the original $mdToast lines are currently commented out:
export class MainController extends BaseController {
static $inject = [
'tableService',
'$mdSidenav',
//'$mdToast',
'$mdDialog',
'$mdMedia',
'$mdBottomSheet'];
constructor(
private tableService: ITableService,
private $mdSidenav: angular.material.ISidenavService,
//private $mdToast: angular.material.IToastService,
private $mdDialog: angular.material.IDialogService,
private $mdMedia: angular.material.IMedia,
private $mdBottomSheet: angular.material.IBottomSheetService) {
super();
var self = this;
}}
The following is the base class. Take note of the injection of $mdToast and the declaration of $mdToast outside of the constructor:
export class BaseController {
static $inject = [
'$mdToast'];
constructor() {
var self = this;
}
private $mdToast: angular.material.IToastService;
openToast(message: string): void {
this.$mdToast.show(
this.$mdToast.simple()
.textContent(message)
.position('top right')
.hideDelay(3000)
);
}}
I tried using $injector as suggested elsewhere on SO, but it didn't work for me. Appreciate any helpful responses!