Я использую Angular 4 и у меня есть два компонента: navbar.component и profile.component. Я могу загрузить изображение профиля с profile.component, и на моей панели навигации я показываю изображение профиля. но когда я загружаю изображение в profile.component, изображение не будет обновляться, и я должен обновить страницу. как я могу обновить его без обновления страницы?
здесь profile.component:
user['profile_pic'] = this.new_profile_pic_name;
}
this.authService.updateProfile(user).subscribe(data => {
if (!data.success) {
consolle.log('err')
} else {
console.log('success')
}
});
и это navbar.component:
ngOnInit()
{
this.authService.userProfile().subscribe(user => {
if (!user.success) {
console.log('err')
} else {
this.user_id = user.user.rows[0].id;
if (user.user.rows[0].profile_pic) {
this.profile_pic = this.profile_pic_dir +
user.user.rows[0].profile_pic;
}
}
});
}
и HTML-код navbar:
<button [md-menu-trigger-for]="user" md-icon-button class="ml-xs">
<img [src]="profile_pic" class="img" *ngIf="profile_pic">
<img src="assets/images/profile/no-pic.jpg" class="img"
*ngIf="!profile_pic">
</button>