Last active
August 10, 2017 17:45
-
-
Save rafaelvicio/bb1645d31ee492f25ea3c98417adcc9d to your computer and use it in GitHub Desktop.
Formulario de Login Angular2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########### Erro apresentado ########### | |
{ MongooseError: Path `login` is required. | |
at ValidatorError (C:\GitHub\eSports-team\Back\node_modules\mongoose\lib\error\validator.js:24:11) | |
at validate (C:\GitHub\eSports-team\Back\node_modules\mongoose\lib\schematype.js:705:13) | |
at C:\GitHub\eSports-team\Back\node_modules\mongoose\lib\schematype.js:750:9 | |
at Array.forEach (native) | |
at SchemaString.SchemaType.doValidate (C:\GitHub\eSports-team\Back\node_modules\mongoose\lib\schematype.js:711:19) | |
at C:\GitHub\eSports-team\Back\node_modules\mongoose\lib\document.js:1408:9 | |
at _combinedTickCallback (internal/process/next_tick.js:73:7) | |
at process._tickCallback (internal/process/next_tick.js:104:9) | |
message: 'Path `login` is required.', | |
name: 'ValidatorError', | |
properties: [Object], | |
kind: 'required', | |
path: 'login', | |
value: undefined, | |
reason: undefined } }, | |
message: 'Usuario validation failed', | |
name: 'ValidationError' } | |
########### Formulario HTML ########### | |
<form novalidate #meuForm="ngForm" (submit)="logar($event)"> | |
<div class="form-group row"> | |
<label for="login">Nome:</label> | |
<input required name="login" #login="ngModel" [(ngModel)]="usuario.login" type="text" class="form-control" id="login" placeholder="Seu login..."> | |
</div> | |
<div class="form-group row"> | |
<label for="senha">Senha:</label> | |
<input required name="senha" #senha="ngModel" [(ngModel)]="usuario.senha" type="password" class="form-control" id="senha" placeholder="Sua senha..."> | |
</div> | |
<div class="row"> | |
<div class="col"> | |
<button type="submit" class="btn btn-primary btn-lg">Entrar </button> | |
</div> | |
<br> | |
<div class="col"> | |
<p><a href="#">Esqueceu sua senha?</a></p> | |
</div> | |
</div> | |
</form> | |
########### Login Componente ########### | |
logar(){ | |
this.service.logar(this.usuario) | |
.then( res => { | |
console.log('Logando...') | |
}) | |
.catch(erro => console.log(erro)) | |
} | |
########### Login Service ########### | |
logar(usuario: UsuarioComponent): Promise<any> { | |
return this.http.post(this.url, JSON.stringify(usuario)) | |
.toPromise() | |
.then( res => { | |
var token = res.headers.get('x-access-token'); | |
if (token) { | |
this._loggedIn.next(true); | |
localStorage.setItem('token', token); | |
} | |
}) | |
.catch( err => console.log(err)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment