Очевидно, вам придется вызывать ngOnInit
на компоненте аватара после изменения конфигурации на нем:
import { Component, OnInit, ViewChild } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
bg = '#000000';
@ViewChild('avatar') private elAvatar: any;
c() {
console.log('before: ' + this.bg);
this.bg = '#' + (Math.floor(Math.random() * 900000) + 100000).toString();
console.log('after: ' + this.bg);
this.elAvatar.ngOnInit();
}
}
И в шаблоне:
<avatar #avatar [background]="bg"></avatar>
<button (click)="c()">Change</button>
Эточто они сделали в этой демонстрации здесь :