How to Make Forms in Angular REUSABLE (Advanced, 2023)

How to Make Forms in Angular REUSABLE (Advanced, 2023)

Decoded Frontend

9 месяцев назад

57,655 Просмотров

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


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

@chaitanyatank3002
@chaitanyatank3002 - 04.12.2023 10:00

I am working on a project which uses angular 10, how should I provide the ControlContainer in viewProviders ? I am not able to figure out how can I solve the circular dependency error.

Ответить
@maximilyukhin5454
@maximilyukhin5454 - 24.11.2023 22:27

Awesome!

Ответить
@rembautimes8808
@rembautimes8808 - 19.11.2023 11:54

Signed up to the course

Ответить
@vladimirv.443
@vladimirv.443 - 10.11.2023 21:42

Interesting idea. What about a template-driven forms?
Does this approach only work with reactive forms?

Ответить
@user-oz3kb5wn4i
@user-oz3kb5wn4i - 09.11.2023 23:05

Hello. Thank you for video. I have one question about this way to use form. What about typed of parent form? If we get value of parent form we know that we have additional key and value but typescript doesn’t know. Please correct me if i am wrong

Ответить
@eduardohernandezanzardo1378
@eduardohernandezanzardo1378 - 07.11.2023 13:17

Great content, best regards from Cuba.

Ответить
@ricardotovar4597
@ricardotovar4597 - 31.10.2023 03:24

With that way, Control value accesor is not necessary?

Ответить
@endlacer
@endlacer - 30.10.2023 23:49

we just use [formControl] Syntax on the Inputs and it works like a charm, there is no need for reference to the parent formgroup. why is that?

Ответить
@vadimkostenko1617
@vadimkostenko1617 - 27.10.2023 21:45

Hey 👋🏻 Thanks for sharing. I just curious how does it work with typed forms? 🤔

Ответить
@innocentmazando3808
@innocentmazando3808 - 27.10.2023 14:14

Now this video has lessons on it.

Based on this I just trimmed an HTML file that had about 2500 lines down to 741.
Thanks @Dymytro :)

Ответить
@davidgarciasantes
@davidgarciasantes - 26.10.2023 23:24

Nice video, I will investigate this solution in more detail, thank you continue as well 💪

Ответить
@diglettt
@diglettt - 25.10.2023 01:23

Ok, you're awesome. Not often people make me subscribe them, keep it up!

Ответить
@gameofnoobgon7199
@gameofnoobgon7199 - 24.10.2023 19:08

Thank you. very useful content.

Ответить
@calbofacundo8549
@calbofacundo8549 - 24.10.2023 17:25

Really thank you man! greatings from Argentina! have a nice day!

Ответить
@halgaska
@halgaska - 23.10.2023 21:53

We have a parent component with several child components, several of which are further nested, and it's ReactiveForm. Instead of implementing CVA for every child component, or using Inputs/Outputs, we are using FormGroupDirective. So into every child component, that is a part of the form, we inject the FormGroupDirective and add the control to the parent form. Have you seen this approach? I would like to double-check somewhere whether this approach is okay and not breaking good practices :D And what would be a better approach, FormGroupDirective or your in the video?

Ответить
@22plowman
@22plowman - 23.10.2023 20:36

is there a git link for the code? Fantastic tutorial btw

Ответить
@janwidmer8985
@janwidmer8985 - 17.10.2023 20:24

@DecodedFrontend we have built a reusable set of form components, where one single input field with label and error message is represented by one component. E.g. text-input, text-area, checkbox-group and so on.

So far, we passed in the reference to the form like at the begin of your video. I will definitely try your approach. Another problem with the Child Components is, that we cannot use change detection stragety onPush in the child componentes (e.g. in text-input component) because then, the form control within the child component does not seem to get notified about the parent form having been submitted and the validation state of the form control changed.

Do you have an idea how that problem could be solved?

Ответить
@khumozin
@khumozin - 17.10.2023 12:15

I was wondering, how do we unit test this in jasmine?

Ответить
@MsEntombed
@MsEntombed - 14.10.2023 12:15

This solution work with FormArray? If it’s not difficult, show in the next video how this is implemented, thanks

Ответить
@lorenzoleonori7623
@lorenzoleonori7623 - 13.10.2023 11:52

Hi! Thanks you for share this amazing feature. I 've two questions.

I use this approach to create reusable input field (text/email/number and so on), select, radio etc... The <form [formGroup]="blablaForm"> reside in separate file and pass in input [controlKey], to the inputFiled component ([formControlName]="controlKey") and the magic appear.

So the question is, what do you think about my solution? It's overkill? There is a simple one solution?
Can I ask you what you think about compare your solution with the FormGroupDirective for create reusable form?

Ответить
@MStoica
@MStoica - 10.10.2023 23:33

I was just about to comment “why not use ControlValueAccesor”… when I realized that you are not declaring the deliveryAddress form control/group in the parent component. This is so cool and makes this even more easy to reuse. Awesome lesson! I really have to get your forms course!

Ответить
@Kiran-lr8gi
@Kiran-lr8gi - 09.10.2023 16:31

why formControlName don't have exportAs ?

Ответить
@sinhue
@sinhue - 09.10.2023 07:27

Amazing content bro great job … 🎊 🎉

Ответить
@beto1972EU
@beto1972EU - 07.10.2023 23:52

shows me an error
Cannot read properties of undefined (reading 'addControl')
at AddressgroupComponent.ngOnInit

parentFormGroup is undefined.

Ответить
@fortinfred
@fortinfred - 04.10.2023 22:15

Not a fan of this teaser video...

Most junior developers will think that it is acceptable to do this ugly inecjection of the parent formGroup and adding the control dynamically instead of using ControlValueAccessor.

I love your videos but this one gets a thumb down.

Ответить
@anhquande
@anhquande - 03.10.2023 18:34

another great video, Thanks

Ответить
@johncerpa3782
@johncerpa3782 - 01.10.2023 18:45

Great video

Ответить
@aram5642
@aram5642 - 30.09.2023 12:07

Another cool video, or should I say: a missing part of Angular docs! I finally understood the resolution decorators Thanks!. Given that the main form model (in this case: AppComponent) is incomplete (the remaining fields are dispersed across other components), how is this going to work with strongly typed forms? Also, if I wanted to author a form AddressGroupComponent that is usable in both ReactiveForms and template driven forms - would I have to author two separate components? I think Angular forms got a bit neglected over time.

Ответить
@NobleOsinachi
@NobleOsinachi - 28.09.2023 09:47

Ответить
@kakhakakhurashvili4203
@kakhakakhurashvili4203 - 27.09.2023 13:25

Avto already did it

Ответить
@neon_342
@neon_342 - 27.09.2023 05:31

Hello @DecodedFrontend, your advanced concepts videos are very helpful. Can you please create a tutorial on how to build a Realtime Video chat web app in Angular 14 using webrtc protocol.

Ответить
@dzivojelic
@dzivojelic - 26.09.2023 19:37

@DecodedFrontend FormArray example would be much appreciated as well :)

Ответить
@ams1ams53
@ams1ams53 - 26.09.2023 18:49

It would be great to make a video about accessability. like how to change font-size for the whole application.

Ответить
@konradkalicinski6831
@konradkalicinski6831 - 25.09.2023 11:07

Thank you Dmytro, you're producing a really great and unique piece of content.
Secondly, although I really like this approach in some cases, I wonder if it doesn't break the typed forms. What if I would like to have a multistep form (order) with items and addresses as separate form groups? I would like to know it upfront, validate everything etc. And with this approach the starting form group has only single field. I feel CVA would be a better choice.
So my question - is there a way to use type in root component with the approach you demonstrated?

Ответить
@sebawinsten7028
@sebawinsten7028 - 24.09.2023 22:34

I dynamic pass form control name and label ita possible

Ответить
@betsegawlemmaamersho1638
@betsegawlemmaamersho1638 - 24.09.2023 17:23

Thanks you for the video.
Please make a video for creating inline-editing feature for angular material table

Ответить
@arthurfedotiew3609
@arthurfedotiew3609 - 24.09.2023 15:56

This was useful indeed Dmytro, thank you! One little thing is NgFrom is also ControlContainer provider and implementor, not only NgModelGroup when talking about TDF

Ответить
@Nikkvv
@Nikkvv - 24.09.2023 04:04

Я недавно чуть не цілий день потратив. Знайшов інше рішення, але це виглядає набагато краще)

Ответить
@mib8254
@mib8254 - 23.09.2023 23:55

why not to use FormGroupDirective and saving the hassle?
This way we make the sub form auto injected

Ответить
@oleksandrvorovchenko8674
@oleksandrvorovchenko8674 - 23.09.2023 21:34

Cool! Thank you!

Ответить
@JulienTeyteau
@JulienTeyteau - 23.09.2023 10:30

Stellar!

Ответить
@soulador
@soulador - 22.09.2023 22:00

Interesting. Won't id's 'zipcode' and 'address' be copied too though and violate valid html? How would you handle that, if it's a problem? Or why is it not?

Ответить
@emrehizli4444
@emrehizli4444 - 22.09.2023 14:51

I have bought the advanced course :D It seems amazing!!!

Ответить
@hamidkadkhoda6966
@hamidkadkhoda6966 - 22.09.2023 12:32

that's awesome, thank you.

Ответить
@andreiarpenti2589
@andreiarpenti2589 - 22.09.2023 10:53

Thanks for the lesson, it is really cool.
Is it possible to use the same approach without adding a new FormGroup, but add just one control to the parent FormControl?

Ответить
@DmitryEfimenko
@DmitryEfimenko - 22.09.2023 07:40

Good little dive into intervals - the ControlContainer, but honestly, it looks like you are on your way to reinvent the wheel - namely the template driven forms

Ответить
@KamelJabber1
@KamelJabber1 - 22.09.2023 04:02

oof, this was pretty slick! thanks for this!

Ответить
@paulovieira8065
@paulovieira8065 - 22.09.2023 02:53

Is there a translation option on the course platform?
My English is still very basic.

Ответить