4
I have already made a modal that receives a name, it sends the controller in the function of inserting new contact. I want to check if this data is already registered in the bank so that it does not register again. Anyone knows how I can do it in Angularjs?
I’ve done it so far...
//Carrega as categorias existentes
var carregaCategorias = function(){
var tam = $scope.categoria.length;
for (var i = 0; i < tam; i++)
$scope.categorias[i] = $scope.categoria[i].nome;
}
//Verifica se já está inserido
$scope.createCategory = function(typeOfCategory, modalId){ //OK
var typeCategory;
var category = $scope.novaCategoria;
if(category == ?? )
When you check if it is already inserted, do you send the "new" object in the verification method? If yes, you could do a
SELECT COUNT
in the table with an equality/LIKE clause.SELECT COUNT(nome) FROM categoria WHERE nome LIKE %dado_procurado%
, for example. And ai, if the result is zero, allow the addition.– mutlei
Good morning! Friend or vc creates a query in the database as mentioned above and returns a value indicating whether or not there is a similar item or you make a request in the API bringing all the records and checks on the front if you already have a similar record, but I believe that a query doing this verification would be ideal.
– pcbsytem