I have Observable that contains big object inside. I want to pass only one property to child component as observable. I can you pipe in component, but I need to create one more observable for it. Can I make it inside html?
// this is service;
this.theObject$ = new BehaviourSubject<TheObject>(null);
this.theObject = {...alot,
title as string,
neededValue as number
};
this.theObject$.next(theObject);
get getTheObject (): Observable<TheObject> {
return this.theObject as Observable;
}
// component:
theObject: Observable<TheObject>;
ngOnInit(){
this.theObject = this.service.getTheObject;
}
// component html:
<div>
<span>{{(theObject | async).title}}</span>
<app-custom-component [neededValue$]="(theObject | async)?.neededValue"></app-custom-component>
</div>
//Custom Component
some: number;
@Input()'neededValue': Observable<number>;
ngOnInit(){
this.neededValue.subscribe(res => {
this.some = res;
})
}
I got an error here:
ERROR TypeError: Cannot read property 'subscribe' of undefined
I think problem is here: (theObject | async)?.neededValue. Is there a way to solve this without extra observables? Also I dont don't to pass to custom component all the big object.
neededValue$vsneededValue).public neededValue$ = this.service.getTheObject().pipe(map(o => o.neededValue));Then use it in your template like[neededValue]="neededValue$ | async"