Code in Controller:
var type = null;
var title = null;
var content = null;
function showMessage(type, title, content) {
$scope.displayMessage = true;
$scope.message = {
type: type,
title: title,
content: content
}
$timeout(function() {
$scope.fadeMessageSuccess = true;
}, 3000);
};
var type = "success";
var title = "Thanks for registering!";
var content = "Your account has successfully been created!";
showMessage(type, title, content);
The above is my code that I'm working with and it's inside a controller currently. It works perfectly however I want to clean it and up and use it in multiple controllers. How do I go about wrapping this part in a function to be used throughout the app and then only having to call the last 4 lines in my controllers:
var type = null;
var title = null;
var content = null;
function showMessage(type, title, content) {
$scope.displayMessage = true;
$scope.message = {
type: type,
title: title,
content: content
}
$timeout(function() {
$scope.fadeMessageSuccess = true;
}, 3000);
};
I only want to have to write the following code whenever I want to show a message:
var type = "success";
var title = "Thanks for registering!";
var content = "Your account has successfully been created!";
showMessage(type, title, content);
The View:
<div ng-controller="AccountCtrl" ng-cloak="">
<div class="ui {{message.type}} message message-overwrite"
ng-class="{'fade': fadeMessageSuccess} "
ng-show="displayMessage">
<div class="header">
{{message.title}}
</div>
<p>{{message.content}}</p>
</div>
</div>