Differences between value and ngValue in Angular 5

Discussão em 'Angular' iniciado por Fel, Novembro 13, 2024.

  1. Fel

    Fel Guest

    Today I realized about an unexpected (for me) behaviour of the reactive forms in Angular 5. The server was receiving from the app an string with the value "null" instead of the null value, whichh is what I wanted.

    I did the following test:

    https://stackblitz.com/edit/angular-rjrspr?file=app/app.component.html

    As you can see in the picture below, if I use [value]="null" in the select, the field is getting "null" (string literal) as value. However, if I use [ngValue]="null" it gets the expected null value.

    [​IMG]

    I thought that using value was intended for reactive forms, while ngValue was for template driven forms. I'd like to know if it's safe to use both in my forms (I always use reactive forms) and if there's any explanation for the different behaviour.

    Thanks!

    Continue reading...

Compartilhe esta Página