问题
I'm trying to validate a form with angular 6. Here's my PUG code:-
.form-group
input.input-lg.form-control(type="text",
placeholder="Your firstname",
name="fname",
#fname="ngModel",
required)
.alert.alert-danger(*ngIf="fname.invalid")
p([hidden]="!fname.errors.required") First name is required`
and I get this error:
Uncaught Error: Template parse errors: There is no directive with "exportAs" set to "ngModel" (" ]#fname="ngModel" required="required"/>
I've already imported the FormsModule in the app.module.ts.
回答1:
I had a simmilar problem which I asked about in this question. Check the comment section. My problem was that i forgot to add the imports: [FormsModule, ...
in the app.module.ts. Maybe this is your problem too.
来源:https://stackoverflow.com/questions/52027573/no-directive-with-exportas-set-to-ngmodel-angular-6