I am able to use to perform invalid input validations, min characters and max characters, eg:
<form name="myForm">
<div class="input-group">
<input type="text" class="form-control" name="cep" ng-model="cep" ng-minlength="5" ng-maxlength="20" placeholder="Digite o CEP" autofocus required>
<span class="input-group-btn">
<button class="btn btn-success" type="submit" ng-click="buscar(cep)">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</button>
</span>
</div>
</form>
<div ng-messages="myForm.cep.$error">
<div ng-message="required" class="alert alert-danger" role="alert">Campo não pode ser vazio.</div>
<div ng-message="minlength" class="alert alert-danger" role="alert">Deve ser acima de 5 caracteres</div>
<div ng-message="maxlength" class="alert alert-danger" role="alert">Deve possuir menos que 20 caracteres</div>
</div>
Now I need to understand how to use the same ng-message service to show a message if my request fails example:
var app = angular.module("buscaCEP",['ngMessages']);
app.controller("buscaCEPCtrl",function($scope,$http){
$scope.buscar = function(cep){
$http.get('https://viacep.com.br/ws/'+cep+'/json/').success(function(data){
$scope.form = data;
}).error(function(){
console.log("Ocorreu um erro inesperado, verifique se os dados digitados estão corretos.");
});
};
});
In http error, I need to send an action to show console.log () message
Example working on plunker