1
I am trying to validate a simple form, where when the user leaves some field blank a div is damaged with this error. Follow the code
var playlistApp = angular.module('playlistApp', []);
playlistApp.controller("LucasCtrl", ['$scope', function($scope) {
var vm = this;
vm.IsErrorNome = false;
$scope.validarCampos = function() {
if ($scope.nome == null) {
vm.IsErrorNome = true;
return;
}
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<body ng-app="playlistApp" ng-controller="LucasCtrl">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="form">
Nome:
<input type="text" class="form-control" ng-model="nome">
<div ng-show="IsErrorNome">Nome em branco</div>
Idade:
<input type="number" class="form-control" ng-model="idade"> Endereço:
<input type="text" class="form-control" ng-model="endereco"> Telefone de contato:
<input type="text" class="form-control" ng-model="endereco">
<br>
<input type="submit" ng-click="validarCampos()" value="Próximo >" class="btn btn-success pull-right">
</div>
</div>
</div>
</div>
</body>
However, the div does not appear when clicking on Ubmit, I debugged by Chrome and saw that the states are being changed... Can anyone help me? Thanks