javascript - ng-model value $scope on controller is "undefined" -
on studies of ionic framework i'm learning controllers, so, got simple code html (above , below following code code generated ionic, didn't touch it)
<div ng-controller="controller"> <ion-content> <img class="indeximg" src="img/saludoindex.jpg"> <br><br> <div class="item item-input-inset"> <label class="item-input-wrapper"> <i class="icon ion-at placeholder-icon"></i> <input type="text" placeholder="dirección de email" ng-model="mail"> </label> </div> <div class="item item-input-inset"> <label class="item-input-wrapper"> <i class="icon ion-locked placeholder-icon"></i> <input type="text" placeholder="contraseña" ng-model="word"> </label><br> </div> <div class="col text-center"> <br><h4><a>¿olvidaste tu contraseña?</a></h4><br><br><br><br><br> <a class="button button-stable button-large" href="templates/register.html"> <b>crear una cuenta gratuita</b></a> </div> </ion-content> <ion-footer-bar class="bar-positive tabs"> <a class="tab-item"> <h4 style="color:white;" ng-click="registrar()">iniciar sesiÓn</h4> </a> </ion-footer-bar> </div>
and javascript
(function (){ var app = angular.module('starter', ['ionic']); var app2 = angular.module('nuevo', []); app.controller('controller', function($scope, $http) { $scope.registrar = function(){ $http.post("http://127.0.0.1:8080/php/conexion.php",{ correo:$scope.mail, pass:$scope.word, }).success(function(data){ console.log("exito"); console.log($scope.mail); }); } }); app2.controller('registrousuario', function($scope, $http){ $scope.nuevousuario= function(){ $http.post("http://127.0.0.1:8080/php/registrousuario.php",{ tipo:$scope.tipo, cedula:$scope.cedula, nombres:$scope.nombre, apellidos:$scope.apellido, email:$scope.email, pass:$scope.contra, indicativo:$scope.indicativo, numero:$scope.numero, }).success(function(data){ console.log($scope.cedula); console.log($scope.nombre); console.log($scope.apellido); console.log($scope.email); console.log($scope.contra); console.log($scope.indicativo); console.log($scope.numero); }); } }); app.run(function($ionicplatform) { $ionicplatform.ready(function() { if(window.cordova && window.cordova.plugins.keyboard) { cordova.plugins.keyboard.hidekeyboardaccessorybar(true); cordova.plugins.keyboard.disablescroll(true); } if(window.statusbar) { statusbar.styledefault(); } }); }) }())
as can see above, it's basic login form, have troubles ng-model="mail" , ng-model="word" in first controller registrar() $scope values, function goes php file, no problems there, but, testing did console print see values of ng-models , throws "exito" firts message , "undefined" value of $scope.mail value, same thing $scope.word value.
why happening? i'm confused, because other controller works perfect, tried change value of var
app = angular.module('starter', ['ionic']);
to
var app = angular.module('starter', []);
but gives me error too. tried declare var app3 value of above, still nothing.
i hope can give me hand this, time.
i believe have initalize variables before function or inside function
e.g
app.controller('controller', function($scope, $http) {
$scope.mail = '';
$scope.word = ''; $scope.registrar = function(){ $http.post("http://127.0.0.1:8080/php/conexion.php",{ correo:$scope.mail, pass:$scope.word, }).success(function(data) { console.log("exito"); console.log($scope.mail); }); } });
hope helps!
Comments
Post a Comment