Reactive Form Validation in Angular: Mastering Best Practices

Поділитися
Вставка
  • Опубліковано 3 січ 2025

КОМЕНТАРІ • 47

  • @MonsterlessonsAcademy
    @MonsterlessonsAcademy  7 місяців тому

    WATCH NEXT: Angular Interview Questions and Answers - Dominate Your Next Interview - ua-cam.com/video/5A_YKlVWMPo/v-deo.htmlsi=2DCn7yspEAAJ2H6l

  • @advance5189
    @advance5189 4 місяці тому

    I always find something new for me in your videos. Pretty good work. Thanks!

  • @ugochukwuumerie6378
    @ugochukwuumerie6378 6 місяців тому

    Awesome lesson

  • @dunmer0992
    @dunmer0992 8 місяців тому

    Very nice. It really hit the spot.

  • @maximkantsura1219
    @maximkantsura1219 5 місяців тому

    Nice guide, thanks for your work

  • @oleksiipopov5143
    @oleksiipopov5143 8 місяців тому

    Great lesson!

  • @RomanWaves
    @RomanWaves 2 місяці тому

    good tutorial thank you! could you also provide the Angular version you are using ? would be nice to know that at the beginning of the tutorials, or did I maybe miss it somewhere?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  2 місяці тому

      You can always check it in the source code under the video

    • @RomanWaves
      @RomanWaves 2 місяці тому

      @@MonsterlessonsAcademy thanks :)

  • @TeddyEDMOND-p6u
    @TeddyEDMOND-p6u 7 місяців тому

    this is nice, in order to unbloat the file i would suggest creating an error component that takes an the errors and formControls and displays them when ever error happens.
    with the right modularity this could save some massive time and allow you DRY code.
    (this is not the subject i know )

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  7 місяців тому

      Sure. You can split it like you want. I just showed the most simple and basic way, so people understand how it works.

    • @sam.s6686
      @sam.s6686 5 місяців тому

      Hi, can you please refer me to an example on how to do that

    • @TeddyEDMOND-p6u
      @TeddyEDMOND-p6u 5 місяців тому

      ​@@sam.s6686 i didn't really find any example of this online.
      however here is what you can do:
      create a component that takes the error object stored in the form. this components goal is to display the error and a detail of this error so you can write all the needed logic there.
      (i suggest you study the shape of the error object)
      then instead of creating a div with ngif or @if
      simply use an instance of this component for each input of your form.
      when there is an error your component should display the error and why it happened.
      note that angular material can display the common errors of a form out of the box.
      you should also read the document on the angular material inputs.

  • @manojv2893
    @manojv2893 Місяць тому

    Why did you write the custom validation functions outside the class component? Are there any pros and cons for that?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Місяць тому +1

      It a just a reusable function so I would put it somewhere together with other validators. Like helpers/custom-validators.ts

    • @manojv2893
      @manojv2893 Місяць тому

      @MonsterlessonsAcademy ok, that's really helpful. I was also reading a bit about dependency injection in Angular and got to know that if we use @Injectable() and inject the service within a class it will create a single instance of it instead of recreating the same instance again and again. However even in my team, my collegues create functions the way you have shown. So I'm starting to question the authenticity of what I read. Can you please clarify???

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Місяць тому +1

      @@manojv2893 We typically use provided in root in a service and it creates a singleton for the whole project. helper function is just a function. It's not an injectable.

    • @manojv2893
      @manojv2893 Місяць тому

      @@MonsterlessonsAcademy just one last doubt. Suppose we call the same helper function 2-3 times within a class, will it create 2-3 instances of the same function unlike the injectables?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  Місяць тому +1

      @@manojv2893 Functions don't create instances. It's just a piece of code.

  • @kanaiyatiwari6748
    @kanaiyatiwari6748 7 місяців тому

    which themes you are using in vscode

  • @fawzzhkz9023
    @fawzzhkz9023 7 місяців тому

    ❤superb

  • @sohailnaseer7251
    @sohailnaseer7251 6 місяців тому

    @if decorator is not working in angular 15. what is the issue?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  6 місяців тому

      It is not available in angular 15. Use *ngFor directive instead.

  • @Brendan2Alexander
    @Brendan2Alexander 7 місяців тому

    So...do reactive forms work in a zoneless environment?

  • @N4suu-t3y
    @N4suu-t3y 7 місяців тому

    what is your fonts

  • @TurboSasa
    @TurboSasa 7 місяців тому

    Why not use form field getter in component ts for example
    `get firstName(): AbstractControl {
    return this.form.get('firstName');
    }`
    and then in template `@if (firstName.invalid ...`

  • @chickenjoy
    @chickenjoy 7 місяців тому

    What if I only want the errors to show when I click outside and not when I'm am still typing so that I will not get distracted or slightly pissed off that I haven't finished typing yet.

  • @karthim9620
    @karthim9620 7 місяців тому

    I need to connect

  • @fadil2671
    @fadil2671 7 місяців тому

    whats the difference with
    form = new FormGroup({
    name: new FormControl(null, [Validators.required, Validators.minLength(8)])
    desc: new FormControl(null)
    })

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  7 місяців тому +1

      There is no difference. You can provide validators if you need to but it is not mandatory

    • @fadil2671
      @fadil2671 7 місяців тому

      @@MonsterlessonsAcademy okay, nice. thanks

  • @deleted-u5g
    @deleted-u5g 7 місяців тому

    A comment for the algorithm

  • @matthewfreedberg3752
    @matthewfreedberg3752 7 місяців тому

    "my speak english very bad. So, my name is Boris. I gotta go home to Albania to work on war factory and build tanks. London is a capital of Great Britain!" Damn, dude, I know it is very important to support all kinds of spreading knowledges, but at first you should work on your English pronunciation and only then play role of youtube blogger. My ears are bleeding right now! And I am still silent about how you look (not event close to Brad Pitt). If it is so necessary to practice English or acting or acting in English, there are so many platforms for it. I don't think that non-public frontend work for IT company brings less income than blogging (but who knows I am not an Angular blogger from USSR). For Christ's sake.