Good morning, I do not work much with front end and I started using the angle with bootstrap soon, my question is: I have a div for presentation of messages, error, success; To change these messages according to the data obtained I ended up creating two functions one for success and another for error where the $ scope, $ timeout and message itself per parameter are passed and these functions are global, to be reused in other controllers , is that correct? If not the best way to do it, follow the functions:
/*Mensagens para operações realizadas com sucesso */
function showMsgSuccess($scope, $timeout, msg){
$scope.mostraMsg = true;
$scope.classMessage = 'alert alert-info default';
$scope.message = msg;
$timeout(function(){
$scope.classMessage = 'alert alert-info fade';
}, 4000);
}
/*Mensagens para operações realizadas com erro */
function showMsgError($scope, $timeout, msg){
$scope.mostraMsg = true;
$scope.classMessage = 'alert alert-danger default';
$scope.message = msg;
$timeout(function(){
$scope.classMessage = 'alert alert-danger fade';
}, 4000);
}
callback example in callback
showMsgError($scope, $timeout, 'Erro ao Buscar Cep!!!');
or html
<div ng-if="mostraMsg" ng-class="classMessage">
<span class="glyphicon glyphicon-exclamation-sign"> <strong>{{message}}</strong></span>
</div>