💥 Angular TYPED Forms: Are You Using Them Correctly?

  Рет қаралды 4,181

Angular University

Angular University

Күн бұрын

Пікірлер: 28
@AngularUniversity
@AngularUniversity Жыл бұрын
This is my first video made specifically for KZbin, please enjoy. 🙂 A full course on Angular Forms is available here - angular-university.io
@WebFluxHub
@WebFluxHub 4 ай бұрын
How is this possible syntactically? TS2729: Property fb is used before its initialization.
@nathanf6526
@nathanf6526 11 ай бұрын
Regarding not explictly using a generic argument, how about if you use a FormControl which is a complex type, and you initialise it with null? The form control's type with be inferred as 'unknown' P.s. thanks for the video.
@AngularUniversity
@AngularUniversity 11 ай бұрын
This is true, but for most forms I think it's OK to initialize strings with the empty string, numbers with 0, etc. It greatly simplifies the form declaration. For most practical cases, there is no downside. 👍
@borisjenicek6059
@borisjenicek6059 Жыл бұрын
What if the form is in the child component and you receive data through input, how to declare the form outside the lifecycle method in this way?
@AngularUniversity
@AngularUniversity Жыл бұрын
the form is best declared as a member variable, to get the full type safety benefits. Check out this video for more details - kzbin.info/www/bejne/n6WVc42lftt1hsU
@RaviMittal84
@RaviMittal84 Жыл бұрын
What about FormArray?
@AngularUniversity
@AngularUniversity Жыл бұрын
works also, with this.fb.array() 👍
@hatsvids
@hatsvids 11 ай бұрын
Thank you for the excellent video. I was just left with a question regarding FormArray. Assuming the suggested "best" way to handle typed forms, how should I deal with FormArrays? In a practical example, where in a form there is a FormGroup with the control for the name and a FormArray for a FormGroup of Addresses (with controls for street, city, zip code), how should I declare the FormArray, assuming that initially there are no entries in the FormArray, as the user has not added/pushed any address yet?
@AngularUniversity
@AngularUniversity 11 ай бұрын
If youdon't have any initial values, then that could be a good example of where using an explicit type would work great. My point in the video was, most of the times you can simplify your forms code by removing the explicit types, as long as you have some initial values for the fields.👍
@hatsvids
@hatsvids 11 ай бұрын
​@@AngularUniversity So, in this example the FormArray would be a good case of the exception to the "rule". Thank you for the clarification.
@happyhappy-jl6yq
@happyhappy-jl6yq Жыл бұрын
Awesome content.
@AngularUniversity
@AngularUniversity Жыл бұрын
Thank you, please enjoy ☺
@antondoit
@antondoit 11 ай бұрын
As always great content
@AngularUniversity
@AngularUniversity 11 ай бұрын
Thank you, much appreciated 😊
@sivuyilemagutywa5286
@sivuyilemagutywa5286 Жыл бұрын
Generic is great if you have a complex interface in my opinion
@AngularUniversity
@AngularUniversity Жыл бұрын
For a more complex form, the type will still be inferred automatically, so not using the generics directly and relying on type inference is actually less work, and it's guaranteed to always be correct. 😊 you can always use generics is needed by some reason, but normally it shouldn't be necessary. In Typescript for many generic-based APIs like the Forms module, many times the generic parameters don't need to be called explicitly, everything happens via type inference. 👍
@paulh6933
@paulh6933 Жыл бұрын
does ur opinion change if ur form has 10+ fields?
@AngularUniversity
@AngularUniversity Жыл бұрын
For a larger form, this is even more true, we could really use that extra type safety to make our code safer. I just used a small example here to keep it simple for the video. 👍
@JohnSourvinos
@JohnSourvinos 10 ай бұрын
Hi, Vasco. Having the form built *outside* of a function (like ngOnInit), looks ugly and hopefully in a future version this will change.
@AngularUniversity
@AngularUniversity 10 ай бұрын
It's unusual in Angular code indeed and an exception. soon the Angular team will start their work on signal forms, so forms are due for an overhaul 😉
@msnathan2321
@msnathan2321 Жыл бұрын
well devilvered
@AngularUniversity
@AngularUniversity Жыл бұрын
Thank you, I'm glad you enjoyed it. 👍 More videos on the way (including shorts), stay tuned. 😊
@abhikarne
@abhikarne 8 ай бұрын
Is it not feasible to use real project , or m I got something wrong
@AngularUniversity
@AngularUniversity 8 ай бұрын
Sure it is, I use it all the time 😊
💥 Angular Mistakes #2: DON'T Overuse RxJs For Doing Simple HTTP #angular
14:03
Angular Mistakes #6: 🛑 STOP Overusing Centralized Stores
20:20
Angular University
Рет қаралды 7 М.
Who is More Stupid? #tiktok #sigmagirl #funny
0:27
CRAZY GREAPA
Рет қаралды 10 МЛН
БАБУШКА ШАРИТ #shorts
0:16
Паша Осадчий
Рет қаралды 4,1 МЛН
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
Typed Forms in Angular
10:59
Angular
Рет қаралды 58 М.
Angular Forms: Build Dynamic Complex Forms Easily
19:31
Monsterlessons Academy
Рет қаралды 9 М.
Don't put your types in .d.ts files
3:54
Matt Pocock
Рет қаралды 144 М.
Deferrable Views - New Feature in Angular 17
15:31
Decoded Frontend
Рет қаралды 25 М.
🚦Angular Signals Game Changer: NgRx Signal State
11:38
Angular University
Рет қаралды 9 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 927 М.
Javascript return vs return await (Crucial Difference)
10:33
Angular University
Рет қаралды 3,1 М.
Knowing this makes Angular typed forms WAY less awkward
5:03
Joshua Morony
Рет қаралды 10 М.
Why did we need Signal Inputs in Angular, again?
12:19
Zoaib Khan
Рет қаралды 2 М.
Who is More Stupid? #tiktok #sigmagirl #funny
0:27
CRAZY GREAPA
Рет қаралды 10 МЛН