我有此表格可以更改用户。当我更改用户数据时,登录名和电子邮件也更改了,密码也没有更新。
<form>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="title">Login<label style="color:#DD0330;">*</label>:</label>
<input type="text" [(ngModel)]='selectedUser.login' class="form-control border-input" name="login" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="title">E-mail<label style="color:#DD0330;">*</label>:</label>
<input type="email" [(ngModel)]='selectedUser.email' class="form-control border-input" name="email" required>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group form-black">
<label class="control-label">Password<label> </label></label>
<input type="password" class="form-control border-input" [(ngModel)]="selectedUser.password" name="password">
</div>
</div>
<div class="col-md-6">
<div class="form-group form-black">
<label class="control-label">Password Confirmation<label> </label></label>
<input type="password" class="form-control border-input" [(ngModel)]="selectedUser.password_confirmation" name="password_confirmation">
</div>
</div>
</div>
</form>
<div class="col-md-6">
<button type="submit" class="btn btn-info btn-fill pull-right" (click)="saveUser(users)">Save</button>
</div>
我做错了什么?如果您需要添加其他内容,请报告。
saveUser(users: User) {
this.servUser.updateUser(this.selectedUser).subscribe(
data => {
console.log(data);
this.loadUsers();
},
error => {
console.log(error);
}
)
}
答案 0 :(得分:2)
尝试一下。
<div class="col-md-6">
<button type="submit" class="btn btn-info btn-fill pull-right" (click)="saveUser()">Save</button>
</div>
,然后在您的组件中
public selectedUser=new User();
saveUser() {
this.servUser.updateUser(this.selectedUser).subscribe(
data => {
console.log(data);
this.loadUsers();
},
error => {
console.log(error);
}
)
}