I've been scouring the internet for information on setting up two controllers in my AngularJS module, but all the answers I find seem to be outdated. I want to have one controller handling $http GET requests and another displaying success or error messages. Is it best to call a method from the second controller with the message to be displayed, or should I use a service or factory for this? Services sound promising, but I'm struggling to implement them in this context.
var module = angular.module('app', []);
module.controller('ApiController', ['$scope', '$http', function ($scope, $http) {
$http.get('/api').
success(function(data){
// call AlertController('success')
}).
error(function(data){
// call AlertController('failed')
});
}]);
module.controller('AlertController', ['$scope', function ($scope) {
$scope.message = {
show_message: true,
type: 'info',
message: "Display message!"
};
}]);
Alternatively, I might want to push incoming alerts onto a global object variable and remove them after display. Can anyone provide guidance on the best approach for this setup?