카테고리 없음

[Angular 2+] [(ngModel)] must need "name" attribute

Juyeon Ji 2020. 10. 13. 18:55

Naming control elements

When you use [(ngModel)] on an element, you must define a name attribute for that element. Angular uses the assigned name to register the element with the NgForm directive attached to the parent <form> element.

The example added a name attribute to the <input> element and set it to "name", which makes sense for the hero's name. Any unique value will do, but using a descriptive name is helpful.

  1. Add similar [(ngModel)] bindings and name attributes to Alter Ego and Hero Power.

  2. You can now remove the diagnostic messages that show interpolated values.

  3. To confirm that two-way data binding works for the entire hero model, add a new binding at the top to the component's diagnostic property.

출처: angular.io/guide/forms