我正在尝试以角度4进行远程登录请求,但是表单提交无法发送,而不是发送请求到localhost。
<form class="form-signin" (ngSubmit)="f.form.valid && login()" #f="ngForm">
<h2 class="form-signin-heading">Log In</h2>
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" id="inputEmail" class="form-control" [(ngModel)]="user.email" name="email" placeholder="Email" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" [(ngModel)]="user.password" name="password" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
</form>
#login.component.ts
login() {
this.authenticationService.login(this.user).subscribe(
data => {
console.log(data)
},
error => {
console.log(error)
});
}
#authentication.service.ts
login(user) {
return this.http.post('http://192.168.6.24:3000/token', JSON.stringify({ username: user.email, password: user.password }))
.map((response: Response) => {
let user = response.json();
if (user && user.token) {
console.log(user);
}
return user;
});
}