I have a form that sends a value (CPF) of a page to be checked for existence in the database. I use an angular controller to send the cpf to service and then to the controller.
Would you have any examples of how to do this?
HTMLCode
</head><body><formmethod="POST">
<div class="form-group">
<label for="cpf" class="">CPF:</label>
<input type="text" name="cpf" ng-model="cpf" >
</div>
<button ng-click="buscarCliente()">Buscar Cliente</button>
</form>
</body>
</html>
Controller code
angular.module('').controller('TesteController', function ($scope, $timeout, MensagemFactory, ) {
var vm = $scope;
vm.buscarCliente = function(){
if (vm.cpf != NULL) {
alert("!");
}
};
}
Services Code
angular.module('').service('Service', function (servers) {
var service = {
getCpf: getCpf
};
function getCpf(){
return $http.get(servers.vendas + 'api/buscarCliente');
}
return service;
});
Code: link