0
我已經設置了一個設備+ rails api並創建了一個註冊組件。 創建用戶並檢入數據庫後,程序僅提交了電子郵件和密碼,即使我在表單的字段中添加了名稱和暱稱。如何使用Angular2token來發布名稱?
Rails的控制檯
User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT ? [["LIMIT", 1]]
=> #<User id: 5, provider: "email", uid: "[email protected]", name: nil, nickname: nil, image: nil, email: "[email protected]", created_at: "2017-09-14 00:48:13", updated_at: "2017-09-14 00:48:14">
註冊組件TS
import { Component, OnInit } from '@angular/core';
import { Angular2TokenService, RegisterData } from 'angular2-token';
@Component({
selector: 'register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent {
registerData: RegisterData = <RegisterData>{};
output: any;
constructor(private _tokenService: Angular2TokenService) { }
onSubmit() {
this.output = null;
this._tokenService.registerAccount(this.registerData).subscribe(
res => {
this.registerData = <RegisterData>{};
this.output = res;
}, error => {
this.registerData = <RegisterData>{};
this.output = error;
}
);
}
}
註冊組件的HTML
<form (ngSubmit)="onSubmit()">
<div class="row">
<ul>
<li>
<input type="text" name="name" placeholder="Name" required [(ngModel)]="registerData.name">
</li>
<li>
<input type="text" name="username" placeholder="Username" required [(ngModel)]="registerData.nickname">
</li>
<li>
<input type="text" name="email" placeholder="Email" required [(ngModel)]="registerData.email">
</li>
<li>
<input type="password" name="password" placeholder="Password" required [(ngModel)]="registerData.password">
</li>
<li>
<button type="submit">Register</button>
</li>
</ul>
</div>