Angular ERROR: NG01352: If ngModel is used within a form tag, either the name attribute must be set or the form
Problem: Der Wert wird im Feld nicht angezeigt und es kommt eine
Fehlermeldung in Developer Angular
edit-article.component.ts:117 ERROR Error: NG01352: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions.
Example 1: <input [(ngModel)]="person.firstName" name="first"> Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}"> |
Lösung:
man muss nur ein name="meinFeld" in das Tag einfügen
<form #f="ngForm" (ngSubmit)="save_create()"> <div *ngIf="article"> <h1>Id:{{idarticle}}</h1>
<input [(ngModel)]="article.title" name="title" placeholder="Title" style="width: 100%" /> <button class="btn mat-raised-button btn-primary" [disabled]="!f.valid" >Save</button> <button (click)="delete_article(idarticle)" *ngIf="idarticle">Delete</button> </div>
</form> |