I’m unable to access the objects inside the $Scope

Asked

Viewed 77 times

0

I’m trying to validate a form, it only records the data if it passes on if ($scope.frmCliente.$$invalid), but the object frmCliente not being accessible within $Scope.

the error that appears in the console:

Referenceerror: yesre is not defined at m.$Scope.cadrastarClientes (client-controller.js:27) at fn (Eval at Compile (angular.js:15126), :4:242) at b (angular.js:16213) at and (angular.js:26592) at m.$Val (angular.js:17994) at m.$apply (angular.js:18094) At Htmlinputelement. (angular.js:26597) At Htmlinputelement.Dispatch (jquery.min.js:3) At Htmlinputelement.q.Handle (jquery.min.js:3) (Anonymous) @angular.js:14199

form code

<div id="cadastro"  class="row" >
   <form name="frmClientes" novalidate ng-submit="cadrastarClientes()"  ng-if="tela == 2 || tela == 3"
      class="form-group">
      <div class="row">
         <h3 ng-if="tela == 2">Alterar Clientes</h3>
         <h3 ng-if="tela == 3">Cadastrar Clientes</h3>
      </div>
      <div  ng-if="tela == 2" class="row">
         <div class="col-md-1">
            <label>ID:</label>
         </div>
         <div class="col-md-4">
            <input  type="text" id="campoText"
               placeholder=""
               class="form-control"  value=""
               ng-model="cliente.id" ng-disabled="true" />
         </div>
      </div>
      <div class="row">
         <div class="col-md-1">
            <label>Nome:</label>
         </div>
         <div class="col-md-5">
            <input type="text" name="campoNome" placeholder="" maxlength="50" ng-minlength="2"
               class="form-control" required
               ng-model="cliente.nome" />
            <div>
               <span ng-show="frmClientes.campoNome.$error.required && frmCliente.campoNome.$dirty">Campo Obrigatorio</span>
               <span ng-show="frmClientes.campoNome.$error.minlength">Nome Ivalido, minimo 2 caracteres</span>
            </div>
         </div>
      </div>
      <div class="row">
         <div class="col-md-1">
            <label>E-mail:</label>
         </div>
         <div class="col-md-4">
            <input type="email" name="campoEmail" placeholder="[email protected]" required class="form-control" ng-model="cliente.email" />
            <span ng-show="frmClientes.campoEmail.$error.required && frmCliente.campoEmail.$dirty">Campo Obrigatorio</span>
            <span ng-show="frmClientes.campoEmail.$error.email">E-mail invalido</span>
         </div>
      </div>
      <div class="row">
         <div class="col-md-2">
            <input type="button"  class="btn btn-default" value="salvar"
               ng-click="cadrastarClientes()" />
            <input type="button"
               class="btn btn-default" value="cancelar" ng-click="cancelar()" /> 
         </div>
      </div>
   </form>
</div>

function in controller responsible for saving

    $scope.cadrastarClientes = function() {
    console.log(yesre);
    if ($scope.frmCliente.$invalid) {
        $http({
            method: 'POST',
            url: 'http://localhost:8080/cliente',
            data: $scope.cliente
        }).then(function(response) {
            console.log(response.data);
            $scope.cliente.nome = null;
            $scope.clientes.push(response.data);
            $scope.carregarClientes();
            $scope.mensagem = false;
        }, function(response) {
            console.log(response.data);
            console.log(response.status);
        });
    } else {
        $scope.mensagem = true;

    }
};

  • Friend, there is no $ivalid, is $invalid. If it doesn’t, you can make a Jsfiddle or Plunker by making your mistake?

  • That was a typo, but other than that, it wasn’t working yet. but then I can fix it, I can’t remember how kkk. I ended up forgetting that topic

  • You must have drawn the line console.log(yesre); because the error is here, it says in the log ReferenceError: yesre is not defined.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.