At it's absolute simplest you can use a service which has a public value:
@Injectable()
export class Base64Share {
image: string
}
(Although in many cases a Subject
that can stream changes to components as the value changes is preferable)
You can then set the image in the parent:
constructor(private imageShare: Base64Share) {
this.name = `Angular! v${VERSION.full}`
}
setImage() {
this.imageShare.image = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
}
And get it in the child:
ngOnInit() {
this.image = "data:image/png;base64, " + this.imageShare.image;
}
child template
<img [src]="image | safeUrl"/>
Live plunker example