0

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.

1
  • 1
    You use ngModel so it's template driven form, try adding FormsModule in NgModule imports Commented Dec 19, 2023 at 2:30

1 Answer 1

1

Import FormModules to your Module

Sign up to request clarification or add additional context in comments.

1 Comment

Thank your for your advice. I imported the FormsModule to my Module.ts. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.