iam new with Angular and i try to create a form as ngForm. My Problem is when the programme is succesfully compiled the form isnt displayed on my site. I think that i have an issue with the "ngForm" directive. A former Error Message was : "[ERROR] NG8003: No directive found with exportAs 'ngForm'" Maybe somebody can help me. This is my code
formular.component.html
<form #employee="ngForm" (ngSubmit)="onSubmit()">
<div class="input">
<div class="form-group">
<label class="label" for="first">Vorname: </label>
<input class="input" id="first" type="text" [(ngModel)]="firstName" name="firstName" placeholder="Vorname" ngModel="angestellter"/>
</div>
<div class="form-group">
<label class="label" for="second">Nachname: </label>
<input class="input" id="second" type="text" [(ngModel)]="lastName" name="lastName" placeholder="Nachname" ngModel="angestellter" />
</div>
<div class="form-group">
<label class="label" for="position">Position: </label>
<input class="input" id="position" type="text" [(ngModel)]="position" name="position" placeholder="Position" ngModel="angestellter" />
</div>
<div class="form-group">
<label class="label" for="salary">Gehalt: </label>
<input class="input" id="salary" type="text" [(ngModel)]="salary" name="salary" placeholder="Gehalt" ngModel="angestellter"/>
</div>
<button type="submit">Senden</button>
</div>
</form>
formular.component.ts
import { Component } from '@angular/core';
import { Angestellter } from '../angestellter';
@Component({
selector: 'app-formular',
templateUrl: './formular.component.html',
styleUrl: './formular.component.css',
})
export class FormularComponent{
constructor(public angestellter: Angestellter){}
onSubmit():void{
console.log("Hallo");
};
}
angestellter.ts
export class Angestellter {
constructor(
public firstName: string,
public lastName: string,
public position: string,
public salary: string,
){}
}
app.component.ts
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { FormularComponent } from './formular/formular.component';
@NgModule({
declarations: [
AppComponent,
FormularComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
ReactiveFormsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Thanks to everyone who answears.
I tried a lot to make the Form bi-directional to the forms model.