Yeah, hmm, my problem is simple, i have a form and i want to take the value of the inputs to send via post request to my server.
In fact, the job is half done, here is the code of the partial view of the form:
<form name="action.clientesCreate" novalidate ng-submit="action.createCliente()" class="actions-form">
<header>Crear cliente</header>
<div class="omi-field">
<label for="nombre">Nombre</label>
<input type="text" name="nombre" ng-model="action.nombre">
</div>
<div class="omi-field">
<label for="apellido">Apellido</label>
<input type="text" name="apellido" ng-model="action.apellido">
</div>
<div class="omi-field">
<label for="cedula">Cédula</label>
<input type="number" name="cedula" ng-model="action.cedula">
</div>
<div class="omi-field">
<label for="tlf">Teléfono</label>
<input type="number" name="tlf" ng-model="action.tlf">
</div>
<div class="omi-field">
<label for="dir">Dirección</label>
<input type="text" name="dir" ng-model="action.dir">
</div>
<div class="omi-field">
<label for="email">e-mail</label>
<input type="email" name="email" ng-model="action.email">
</div>
<div class="buttons">
<input type="submit" value="Crear" class="omi-btn">
</div>
And, the test controller (ignore the inject for now, it's just a service):
(function(){
'use strict';
angular
.module('omi.controllers')
.controller('clientesAtcionsCtrl', clientesActions);
clientesActions.$inject = ['cliente']
function clientesActions () {
/* jshint validthis: true */
var vm = this;
var clienteData = {
_id: vm.cedula,
nombre: vm.nombre,
apellido: vm.apellido,
direccion: vm.dir,
telefono: vm.tlf,
email: vm.email
};
vm.createCliente = function() {
console.log(clienteData);
};
}
})();
Edited: And here is the state config (all of the other states works fine):
/* Acciones de clientes */
.state('clientesActions', {
url: '/actions/clientes',
templateUrl: 'js/partials/actions.clientes.html',
controller: 'clientesAtcionsCtrl',
controllerAs: 'action'
})
.state('clientesActions.create', {
url: '/create',
templateUrl: 'js/partials/actions.clientes.create.html'
})
.state('clientesActions.edit', {
url: '/edit',
templateUrl: 'js/partials/actions.clientes.edit.html'
})
.state('clientesActions.remove', {
url: 'remove',
templateUrl: 'js/partials/actions.clientes.remove.html'
})
Well, when i send the data, the log retreaved to me is something like this:
Object { _id: undefined, nombre: undefined, apellido: undefined, direccion: undefined, telefono: undefined, email: undefined }
All is undefined, so what i'm doing wrong? I defined the model, and the "ControllerAs" property is defined on the respective State (i'm using ui-router).
Some idea?
Aucun commentaire:
Enregistrer un commentaire