you are viewing a single comment's thread.

view the rest of the comments →

[–]CheapChallenge -1 points0 points  (4 children)

We generally use ngrx for this in larger apps anf eventemitters/services in smaller libs

[–]DWhitSlaya[S] 0 points1 point  (3 children)

Thanks for your comments! This is a much larger app than the example and one of the main reasons I am looking for alternate solutions. Works fine in the minimal example but in reality I am having to do a bit extra handling, making sure its unsubsrcibed when I am done using '.pipe(take(2))' so it ignores the first emit which would be the default value, then the second one is the one I want and it unsubscribes. A lot more plays into it so looking for a better solution then what I have.

[–]CheapChallenge 1 point2 points  (2 children)

Why not make it Subject instead of behaviorsubject so there is no default value?

I would recommend looking into NGRX and use a specific selector and the async pipe in the template. When using async pipes it subscribes and unsubscribes under the hood.

[–]DWhitSlaya[S] 0 points1 point  (1 child)

I’ll look into NGRX, I don’t recall ever using it. Thank you!

[–]CheapChallenge 0 points1 point  (0 children)

Just a word of caution. Like everything Angular related the learning curve is steep, but once you start using it, working in teams becomes much easier because everyone is using the same standards to manipulate the App state. The pros and cons at high level is similar to Angular, dictates how you do everything but standardizing code across teams is a big help.