Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

formControlName with or without brackets?

what is the difference between using formControlName inside brackets and without brackets? In the dynamic form tutorial formcontrolname is used inside brackets

[formControlName]="dyncontrol.key"

but in other tutorials i have seen it without them

formControlName="name"
like image 706
Armando Avatar asked Sep 14 '16 17:09

Armando


1 Answers

Here's from the Template Syntax documentation:

Remember the brackets

The brackets tell Angular to evaluate the template expression. If we forget the brackets, Angular treats the string as a constant and initializes the target property with that string. It does not evaluate the string!

Don't make the following mistake:

<!-- ERROR: HeroDetailComponent.hero expects a
Hero object, not the string "currentHero" -->
<hero-detail hero="currentHero"></hero-detail>
like image 61
Paul Samsotha Avatar answered Sep 19 '22 14:09

Paul Samsotha