我有一个显示用户照片的表格。每次更改用户密码时,照片将从表单中消失。我已经尝试过使用表单的图像,但是并没有解决。密码更改是通过onSubmit完成的。
HTML:
<form (ngSubmit)="onSubmit($event)">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Configuração do Usuário: <b> {{userId?.name}} </b></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="example-container" style="width: 100%; margin: auto; margin-top: 2%">
<img class="img-modal" style="border-radius: 50%; width: 60px; height: 60px;" src={{userId?.photo}}>
<div class="example-container password-width">
<mat-form-field>
<input matInput placeholder="Alterar a Senha" [type]="hide ? 'text' : 'password'" [(ngModel)]="senha" name="senha">
<mat-icon matSuffix (click)="hide = !hide">{{hide ? 'visibility' : 'visibility_off'}}</mat-icon>
</mat-form-field>
</div>
<app-panel-config-user></app-panel-config-user>
</div>
</div>
<div class="modal-footerButtonConfig">
<button type="button" class="btn btn-danger btn-sm buttonConfig" *ngIf="userId?.status == 1">Desativar
Usuário</button>
<button type="button" class="btn btn-success btn-sm buttonConfig" *ngIf="userId?.status == 0">Ativar
Usuário</button>
<button type="button" class="btn btn-sm buttonConfig buttonColor" style="background-color: #6239BD; color: white" *ngIf="userId?.is_admin == 0">Tornar Administrador</button>
<button type="button" class="btn btn-sm buttonConfig buttonColor" style="background-color: #6239BD; color: white" *ngIf="userId?.is_admin == 1">Remover Administrador</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Fechar</button>
<button type="submit" class="btn btn-sm buttonColor" style="background-color: #6239BD; color: white">Salvar</button>
</div>
</form>
代码更改密码:
onSubmit(
userPass: UserPass,
messageSucess: string = 'Senha alterada com Sucesso!',
messageError: string = 'Falha ao alterar a senha.',
action: string = '') {
userPass.password = this.senha;
return this.userService.putPass(this.idUser, userPass).subscribe(response => {
if (!response) {
console.log(Error);
} else {
this.userId = response;
if (this.userId['success'] === true) {
this.senha = '';
this.snackBar.open(messageSucess, action, {
duration: 4000,
panelClass: ['success-class']
});
} else {
this.snackBar.open(messageError, action, {
duration: 4000,
panelClass: ['error-class']
});
}
}
});
}
答案 0 :(得分:2)
您的问题是线路
this.userId = response;
您正在将userId设置为响应({success: true}
)-但响应不是userId!
删除此行,它应该可以再次工作。