angular - 带或不带括号的 formControlName?

标签 angular angular2-forms

在括号内使用 formControlName 和不在括号内有什么区别?在动态表单教程中 formcontrolname 被用在方括号内

[formControlName]="dyncontrol.key"

但在其他教程中我看到没有它们

formControlName="name"

最佳答案

这里来自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>

关于angular - 带或不带括号的 formControlName?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39496787/

相关文章:

javascript - 如何将点击事件绑定(bind)到 angular2 模板插值?

javascript - Angular 4选中多个复选框

Angular 2 字形图标未显示

javascript - 函数 ngOnChanges() 在 Angular 5 中不起作用

Angular - 强制 react 形式在单元测试中有效

javascript - Angular 动态表单组输入

html - 在 Angular 2 中按表单编辑值

Angular 2 : validation for &lt;input type ="file"/> won't trigger when changing the file to upload

typescript - Angular2 (beta3) "expression has changed after it was checked"更新表单值

angular - 何时使用 FormGroup 与 FormArray?