gpt4 book ai didi

angular - 这里没有将 "exportAs"设置为 "ngForm"的指令

转载 作者:太空狗 更新时间:2023-10-29 18:13:34 25 4
gpt4 key购买 nike

我正在使用以下代码在 angularjs 2.0 中提交表单,但出现错误,没有将导出设置为 ngForm 和 ngModel 的指令,但我正在使用。以下是我的表格:

<form name="form" (ngSubmit)="f.form.valid && register()" #f="ngForm" novalidate>
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !username.valid }">
<label for="firstName">First Name</label>
<input type="text" class="form-control" name="firstName" [(ngModel)]="model.firstName" #firstName="ngModel"
required/>
<div *ngIf="f.submitted && !firstName.valid" class="help-block">First Name is required</div>
</div>
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !username.valid }">
<label for="lastName">Last Name</label>
<input type="text" class="form-control" name="lastName" [(ngModel)]="model.lastName" #lastName="ngModel" required/>
<div *ngIf="f.submitted && !lastName.valid" class="help-block">Last Name is required</div>
</div>
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !username.valid }">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" [(ngModel)]="model.username" #username="ngModel" required/>
<div *ngIf="f.submitted && !username.valid" class="help-block">Username is required</div>
</div>
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !password.valid }">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" [(ngModel)]="model.password" #password="ngModel"
required/>
<div *ngIf="f.submitted && !password.valid" class="help-block">Password is required</div>
</div>
<div class="form-group">
<button [disabled]="loading" class="btn btn-primary">Register</button>
</div>
</form>

我还使用以下代码在 app.module.ts 中导入 FormsModule:

import { FormsModule } from '@angular/forms';

@NgModule({
imports: [BrowserModule,
FormsModule
],

最佳答案

我得到了解决方案,实际上我在主 module.ts 文件中使用了 import formModule。

我们必须在特定模块内部使用,在我的例子中它在文件夹 student 中,因为学生我将我的模块名称保存在里面,这里有 student.module.ts 文件,这里我们需要导入 formModule。

关于angular - 这里没有将 "exportAs"设置为 "ngForm"的指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43406053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com