I have an observable that I want to modify.
private userProposalConversatorAfterLogin = new BehaviorSubject<any>([]);
getUserProposalConversatorAfterLogin$ = this.userProposalConversatorAfterLogin.asObservable();
currentUserProposalConversatorAfterLoginValue():ParcelModel[] {
return this.userProposalConversatorAfterLogin.value;
}
setUserProposalConversatorAfterLogin(x) {
this.userProposalConversatorAfterLogin.next(x);
}
and here is the result with the subscription(this.getUserProposalConversatorAfterLogin$.suscribe(proposal))
{
id:1,
messages:[{id:'1', comments:'hello'}, {id=2, comments:'aaa'}, .....]
}
I want to add a new message to the messages array for exemple: {id=3, comments:'oooo'} and and when i go to subscribe again i want to get:
{
id:1,
messages:[{id:'1', comments:'hello'}, {id=2, comments:'aaa'}, {id=3, comments:'oooo'} .....]
}
i tried many way but no success
getUserProposalConversatorAfterLogin$.pipe(
switchMap(x => {
const new_array = (x.filter(x => x['id'] === proposal_identifiant))
console.log(new_array);
if (new_array && new_array.length >=1) {
new_array[0]['message_proposal_identifiant'].push(new_message);
console.log(new_array[0]['message_proposal_identifiant']);
}
return new_array
}),
share(),
distinctUntilChanged(),
)
when i subscribe again i don't see the new value. I think we need to modify userProposalConversatorAfterLogin but how?
I tried with this.userProposalConversatorAfterLogin.next(val)
but it adds just a new object
Thank you in advance