When you need to pass an Observable to another component, it's best practice to use getters and setters.
Imagine you're passing an Observable called myObservable$ asynchronously to a component:
<dumb-component [myvalue]="myObservable$|async">
Inside the dumb component, there is a member variable called myvalue.
DumbComponent:
class DumbComponent implements OnInit {
private _myvalue;
get myvalue() {
return this._myvalue;
}
@Input()
set myvalue(value) {
this._myvalue = value;
if (value) {
// assuming we expect an array with at least one element
if (value.length > 0) {
// manipulate value[0].title or perform other actions
// because our value is now populated
}
}
}
}
In the example above, the Observable emits three values:
1. undefined
2. []
3. an array of elements
This example specifically deals with arrays.
If you're dealing with a single non-array value, you can omit the second check (if statement). Feel free to add your own checks to ensure the validity of the value passed to the setter method.