简体   繁体   English

Angular / NgForm / NgModel指令错误:没有将“ exportAs”设置为“ ngForm”的指令

[英]Angular/ NgForm/NgModel directives error : There is no directive with “exportAs” set to “ngForm”

I have a asp.net core/Angular project. 我有一个asp.net核心/ Angular项目。 In my app.module.client.ts file, i'm importing the '@angular/forms' as below: 在我的app.module.client.ts文件中,我正在导入“ @ angular / forms”,如下所示:

 import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { sharedConfig } from './app.module.shared'; @NgModule({ bootstrap: sharedConfig.bootstrap, declarations: sharedConfig.declarations, imports: [ BrowserModule, FormsModule, HttpModule, ...sharedConfig.imports ], providers: [ { provide: 'ORIGIN_URL', useValue: location.origin } ] }) export class AppModule { } 

My component is configured like this: 我的组件配置如下:

 import { Component } from '@angular/core'; import { NgForm } from '@angular/forms'; import { Operator } from '../shared/operator.model'; @Component({ selector: 'operator-form', template: require('./operator-form.component.html') }) export class OperatorFormComponent { model = new Operator("Login", "Name", "Last name", "password"); submitted = false; onSubmit() { this.submitted = true; } // TODO: Remove this when we're done get diagnostic() { return JSON.stringify(this.model); } } 

My template is configured as below: 我的模板配置如下:

  <form #formOperator="ngForm"> <div class="form-group"> <label for="login">Login</label> <input type="text" class="form-control" id="login" required [(ngModel)]="model.login" name="login" /> </div> <div class="form-group"> <label for="firstName">First Name</label> <input type="text" class="form-control" id="firstName" required [(ngModel)]="model.firstName" name="firstName" /> </div> <div class="form-group"> <label for="lastName">Last Name</label> <input type="text" class="form-control" id="lastName" required [(ngModel)]="model.lastName" name="lastName" /> </div> <div class="form-group"> <label for="password">Password</label> <input type="text" class="form-control" id="password" required [(ngModel)]="model.password" name="password" /> </div> <div class="form-group"> <label for="expirationDate">Valid until</label> <input type="date" class="form-control" id="expirationDate" [(ngModel)]="model.validUntil" name="expirationDate" /> </div> <button type="submit" class="btn btn-success">Submit</button> </form> 

Unfortunately i've got the error: There is no directive with "exportAs" set to "ngForm" 不幸的是,我遇到了错误:没有将“ exportAs”设置为“ ngForm”的指令

Any idea? 任何想法?

Thanks! 谢谢!

When you create an angular project with the command "dotnet new Angular", the app.module is divided in three files: app.module.client.ts, app.module.server.ts and the app.module.shared.ts. 使用命令“ dotnet new Angular”创建一个角度项目时,app.module分为三个文件:app.module.client.ts,app.module.server.ts和app.module.shared.ts。

In order to import properly the package '@angular/forms' you have to add it in the app.module.shared.ts or to add it in the client and the server files. 为了正确导入包“ @ angular / forms”,您必须将其添加到app.module.shared.ts或将其添加到客户端和服务器文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular:“exportAs”设置为“ngForm”的错误无指令 - Angular: Error no directive with "exportAs" set to "ngForm" Angular2 错误:没有将“exportAs”设置为“ngForm”的指令 - Angular2 Error: There is no directive with "exportAs" set to "ngForm" Angular 4-没有将“ exportAs”设置为“ ngForm”的指令 - Angular 4 - There is no directive with “exportAs” set to “ngForm” angular 中没有将“exportAs”设置为“ngForm”的指令 - There is no directive with "exportAs" set to "ngForm" in angular 没有将“exportAs”设置为“ngForm”的指令 - There is no directive with “exportAs” set to “ngForm” Angular2问题:“exportAs”设置为“ngForm”没有指令 - Angular2 issue: There is no directive with “exportAs” set to “ngForm” Angular 6表单模板错误:“没有将“ exportAs”设置为“ ngForm”的指令” - Angular 6 form template error: 'There is no directive with “exportAs” set to “ngForm”' TypeScript- 的 Angular 框架错误 - “没有将 exportAs 设置为 ngForm 的指令” - TypeScript-'s Angular Framework Error - "There is no directive with exportAs set to ngForm" 这里没有将“exportAs”设置为“ngForm”的指令 - here is no directive with “exportAs” set to “ngForm” Angular `12.1.2 错误 NG8003:未找到带有 exportAs &#39;ngForm&#39; 的指令 - Angular `12.1.2 error NG8003: No directive found with exportAs 'ngForm'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM