A trick to make your Angular Reactive Forms more... *Reactive*

A trick to make your Angular Reactive Forms more... *Reactive*

Joshua Morony

2 года назад

14,943 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@ponderwonder
@ponderwonder - 30.09.2023 15:47

Love discussion on reactive (imperative) forms.

One strategy we employ is to build our reactive view model (the state of the page and form) and then use tap to imperatively update the form based on the view model.

Then we do everything in rxjs knowing that our form will update off the back of it.

Your solution is essentially the same. It's encapsulating the imperative parts inside a reactive wrapper.

Ответить
@harleybussell9119
@harleybussell9119 - 25.05.2023 06:38

One issue using this style is losing form state if the observable updates.
If the UserService sends an update the form will get recreated and loose an changes which may be what you want but not always.
In this example it may not be a big issue but could become a problem following this pattern when you using multiple observables that can fire at different times.
I've generally preferred the imperative solution as can create the form once and patch its value over time as async data comes in.

Ответить
@GdeVseSvobodnyeNiki
@GdeVseSvobodnyeNiki - 11.05.2023 23:34

Now i need to figure out how do i get rid of subscription to form valueChange observable.

Ответить
@mawill432
@mawill432 - 02.05.2023 19:41

Thanks for the informative video! I appreciate the level of depth you go to in this tutorial!

Ответить
@Fedotenko2
@Fedotenko2 - 18.04.2023 20:30

Would this approach also work for a dynamic form that has a formarray?

Ответить
@who4mi853
@who4mi853 - 28.02.2023 14:06

How would you handle a case where you need to get valueChanges from a field to do something else like changing the field mask dinamically or calling an api?

Ответить
@andrewhoward6898
@andrewhoward6898 - 22.02.2023 11:52

Have you ever had a situation where you’ve used the async pipe just to trigger some logic but not to necessarily render something on screen?

I have a situation where I need to lookup some things from the url querystrings, lookup an api and then save to a cookie.

I know using async pipe is the preferred way over manually subscribing so would you still use it in this situation?

Ответить
@irohwavez
@irohwavez - 16.11.2022 20:58

Started using NGRX ComponentStore after seeing your recent videos and ran into a snag with the forms. This video cleared it right up. Thanks!

Ответить
@IagoCCampos
@IagoCCampos - 28.10.2022 20:16

How do you handle erros with the async pipe on the reactive aproach?

Ответить
@colinstringer561
@colinstringer561 - 10.10.2022 15:07

Hey Josh, I have a question, but first: your videos have given me a better approach to building my Angular for which I'm very grateful!

So my question has to do with this video.
I'm building a parent component with a users$ observable that passes a users array to a child component.
In the child I have a mat-table with lots of built in functionality, but some of its changes need to be passed to the parent.
Example: the mat-table in my child component registers changes made in sorting, but the parent component needs to know about the sorting changes to send a new request to my API (through the service). What's a clean approach here? Right now I'm using the @Output function to pass a Sort object to my parent, but that feels too imperative. I'd prefer to link the stream of MatSort and the UserService together somehow, but now sure how?

Ответить
@andrewhoward6898
@andrewhoward6898 - 03.10.2022 16:03

Instead of creating a child component each time (which would cause lots of files), could we use the ngtemplateoutlet to keep all the logic in 1 place?

Ответить
@JayCeeGee
@JayCeeGee - 25.08.2022 04:39

Great video. Can't you use .patchValue(this.user) to patch the object into the existing form all at once instead of doing it for each value name/email/bio? Your videos are helping me a ton with rxjs. Keep up the good work!

Ответить
@franciscogiordano3809
@franciscogiordano3809 - 08.01.2022 07:57

Very good!!!

Ответить
@vincent-thomas
@vincent-thomas - 31.12.2021 17:02

in the component you created you could just replace the empty strings with the values in the @Input() user? Code becomes much cleaner that way. No need for ngOnInit() {}

Ответить
@ArchiRuban
@ArchiRuban - 25.12.2021 12:58

Nice! Just wished you explained what that “else” statement was in *ngIf

Ответить
@gabriellenon3257
@gabriellenon3257 - 23.12.2021 04:43

About reactive programming, I think that as much your application grows, the code gets more difficult to understand. And what if you had more code logic before updating the user, it wouldn't be hard to understand, and even to other programmers maintain the code as well? I really don't know if the pros of reactive programming overcome its drawbacks, mainly on big applications and considering the know-how to achieve. But, I'm excited to watch and learn more about angular + ionic + reactive programming, great content!

Ответить
@SampathLokuge
@SampathLokuge - 22.12.2021 16:38

Nice! But we do not need to use `Public` with Typescript since it is `Public` by default.

Ответить
@TayambaMwanza
@TayambaMwanza - 22.12.2021 14:07

Please make an angular specific playlist, would like to watch a lot of your angular specific vids, I see you have ionic playlist. I think stufflike this can go into just angular.

Ответить