1

I'm having a bit of trouble with angular was hoping you could lend me a hand.

I have this HTML code:

</head>
  <body ng-app="starter" ng-controller="editarCtrl">
        <ion-pane>
            <ion-header-bar class="bar-stable">
                <center>
                    <h1 class="title">Agregar Clientes</h1>
                </center>
            </ion-header-bar>

            <ion-content  ng-init="init()">

                <center>
            <img src="\img\ds-firebird-logo-500.png" width="30%">
          </center>
                <center>
                    <button class="button button-possitive" ng-click="addImage()">Editar Foto</button>
                </center>       
                <div class="list">
                    <label class="item item-input item-stacked-label">
                        <span class="input-label" >Nombre</span>
                        <input type="text" placeholder="Escriba su nombre" ng-model="dato_Nombre" >
                    </label>
                    <label class="item item-input item-stacked-label">
                        <span class="input-label">Apellido Paterno</span>
                        <input type="text" placeholder="Escriba su apellido paterno" ng-model="dato_ApPat">
                    </label>
                    <label class="item item-input item-stacked-label">
                        <span class="input-label">Apellido Materno</span>
                        <input type="text" placeholder="Escriba su apellido materno" ng-model="dato_ApMat">
                    </label>
                    <label class="item item-input item-stacked-label">
                        <span class="input-label">Dirección</span>
                        <input type="text" placeholder="Escriba su dirección" ng-model="dato_Direccion">
                    </label>
                <label class="item item-input item-stacked-label">
                  <span class="input-label">Teléfono</span>
                  <input type="text" placeholder="Escriba su teléfono" ng-model="dato_Tel">
                </label>
                    <label class="item item-input item-stacked-label">
                        <span class="input-label">Email</span>
                        <input type="text" placeholder="Escriba su correo" ng-model="dato_email">
                    </label> 
                <center>
              <button class="button button-possitive" ng-click="editarCliente()">Actualizar</button>
              <button class="button button-positive" ng-click="eliminarUsuario()">Eliminar</button>
            </center>    
                </div>              
        </ion-content>
    </ion-pane>
  </body>

And this is my code for my ng-Controller which is called on start in the body: .controller('editarCtrl', function($scope, $http) {

  .controller('editarCtrl', function($scope, $http) {

    $scope.init = function () {
        $scope.idUsuario=localStorage.getItem("idUsuario");
        $scope.dato_Nombre=localStorage.getItem("dato_Nombre");
        $scope.dato_ApPat=localStorage.getItem("dato_ApPat");
        $scope.dato_ApMat=localStorage.getItem("dato_ApMat");
        $scope.dato_Tel=localStorage.getItem("dato_Tel");
        $scope.dato_Direccion=localStorage.getItem("dato_Direccion");
        $scope.dato_email=localStorage.getItem("dato_email");

        localStorage.clear();




    }

    $scope.editarCliente=function(){
         //debugger;

         $http.get("http://salon.klovuz.com/updateClient.php?"+'idUsuario='+$scope.idUsuario+'&'
            +'dato_Nombre='+$scope.dato_Nombre+'&'
            +'dato_ApPat='+$scope.dato_ApPat+'&'
            +'dato_ApMat='+$scope.dato_ApMat+'&'
            +'dato_Direccion='+$scope.dato_Direccion+'&'
            +'dato_Tel='+$scope.dato_Tel+'&'
            +'dato_email='+$scope.dato_email).success(function(response) {alert("Registro actualizado");
            //debugger;
            location.href = "viewClient.html";});

    }

This html is opened by an href on a function, In that function I set the values of my localStorage data, which is then set when running the ng-init="init()" function.

My problem is that if I then modify that input text and call my ng-click="editarCliente()" function, I do not get the input values, instead, I get the ng-model name (Example: in my debugger, the value of dato_Nombre="dato_Nombre")

I know this may not be the best way of calling a php function too, I'm just new to angular and I'm trying to figure out how this works.

Omaruchan
  • 403
  • 1
  • 5
  • 12
  • do follow `dot rule` while defining `ng-model` like create one model inside your controller `$scope.model = {}` and do append all the properties in it when using it as `ng-model` do use `ng-model="model.dato_Nombre"` will do the trick – Pankaj Parkar Sep 13 '15 at 23:13
  • I just pasted your code into plunkr: http://plnkr.co/edit/I8qMGt?p=preview and it seems to work (I do the console log for the url)... So there is something wrong with your PHP part? – mrak Sep 13 '15 at 23:18
  • BTW use a "normal" way to pass the query parameters to [$http](http://stackoverflow.com/questions/13760070/angularjs-passing-data-to-http-get-request) – mrak Sep 13 '15 at 23:22
  • @PankajParkar do you mean I should do something like: `$scope.model={$idUsuario,$dato_Nombre,$dato_ApPat,$dato_ApMat,$dato_Tel,$dato_Direccion,$dato_email};` and then do a `$scope.model.MyData` on each php variable on my `$http.get();`? – Omaruchan Sep 13 '15 at 23:57

0 Answers0