Struggling to find the right title for this query, I'm diving into Angular and using ngMaterial. Currently, I have a toast set up through an Angular factory.
app.factory('notify', ['$mdToast', '$animate', function($mdToast, $animate) {
return {
showToast: function(msg) {
var toast = $mdToast.simple()
.content(msg)
.action('Close')
.highlightAction(false)
.position('top right');
$mdToast.show(toast).then(function() {
//
});
}
}
}]);
Everything works smoothly when there's a button on the page triggering the toast. But now I also have socket.io running with node monitoring redis for updates to display notifications. The challenge is integrating the factory to show the toast in this scenario.
socket.on('notification.new', function (data) {
//call factory here to show toast
console.log(data);
});
I understand that if it was within a controller, I could simply use:
angular.element().scope().showToast(data)
However, I want to avoid creating an element solely for housing the controller to call the function.