我正在使用Angular 4,我有一个组件,我想更改我的用户当前照片..所以显示当前用户照片的HTML代码如下..
我会尽力:我用 Angular 4, 想在组件中修改用户头像。目前展示用户头像的 HTML 代码如下:
<div class="profilphoto">
<img src= {{currentphoto}}>
</div>
currentphoto 包含当前用户的照片 URL,我从 Firebase 获取它。然后,我展示了一组照片供用户选择,并使用表单更改其个人资料照片。提交代码如下,可以正常工作:
onSubmit = function(form) {
this.photoUrl = form.photoUrl;
firebase.database().ref("users/"+this.authService.cusername+"/photo").update({
url: form.photoUrl
}).then(()=>{
this.currentphoto = this.authService.photourl;
console.log("currentphoto:"+this.currentphoto);
}
);
}
除了当前照片的值已更改并更新了数据库URL,一切都正常,但是HTML仍然显示以前用户的图像,这很烦人(如果我刷新页面,则显示新的个人资料图像)。有没有办法可以使其更改?<div class="profilphoto">
<img src= {{currentphoto}}>
</div>
当检测到currentphoto值发生改变时,显示具有新src值的图像?
[src]="currentphoto"
吗? - jonrsharpe