I'm trying to make a form with angularjs 1.5 to obtain the token of a server, but when clicking, I do not get any result or error message.
Use AngularUI Router to set the route of the form ...
// otras rutas
.state('login', {
url: '/login',
templateUrl: '/app/auth/_login.form.html',
controler: 'LoginController',
controllerAs:'in'
});
// otras rutas
And I can visualize my form correctly:
<!-- Archivo: /app/auth/_login.form.html -->
<div class="row">
<div class="offset-sm-3 col-sm-6">
<h2>Formulario de Ingreso</h2>
<form role="form" name="form">
<div class="form-group">
<label for="username">Nombre de Usuario</label>
<input type="text" data-ng-model="in.credentials.username" name="username" id="username" class="form-control" required />
<span></span>
</div>
<div class="form-group">
<label for="password">Contraseña</label>
<input type="password" data-ng-model="in.credentials.password" name="password" class="form-control" id="password" />
</div>
<div class="form-actions">
<button data-ng-submit="in.login(in.credentials)" type="submit" id="submit" class="btn btn-primary">Ingresar</button>
</div>
</form>
</div>
</div>
On the send button, I set that when I click, I will call the function in.login()
with credentials
as parameter. This is the controller.
(function(angular){
'use strict';
function LoginController($scope, $rootScope, auth, session){
var self = this;
var _credentials = $scope.credentials;
var _login = function(_credentials){
// console.log(_credentials);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ Esta línea **nunca se ejecuta**
auth
.logIn(_credentials)
.then(function(){
_user = session.getUser();
});
};
self.login = _login;
self.credentials = _credentials;
}
LoginController.$inject = ['$scope', '$rootScope', 'auth', 'session'];
angular.module('cmi')
.controller('LoginController', LoginController);
})(angular);
The dependencies auth
and session
are services that request the Token and save it in LocalStorage
and, according to me , its functioning is already verified.
Problem
When you click on the Enter button, nothing happens. There are no error messages in the console and the debug line I placed inside _login()
never runs.
I would like to know what I am doing wrong and how to correct my error.
The expected result is as follows: I type the username and password and press the send button. These two data are passed to the service auth
that sends them to the server that returns a token. But I can not get past the first step.
Thank you.