gpt4 book ai didi

Angular - 没有将 "exportAs"设置为 "ngModel"的指令

转载 作者:太空狗 更新时间:2023-10-29 17:06:08 25 4
gpt4 key购买 nike

以下是 AngularJS 项目中的文件。正如一些帖子中所建议的,我添加了:

ngModel name="currentPassword" #currentPassword="ngModel 

在输入字段中,但仍然出现错误。

package.json

.........
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
...............

change-password.component.html

<form #f="ngForm" [formGroup]="changePasswordForm">
<div class="form-group">
<label for="currentPassword">Current Password</label> <input
placeholder="currentPassword" ngModel name="currentPassword"
#currentPassword="ngModel" id="currentPassword"
name="currentPassword" type="text" class="form-control" required
minlength="6" formControlName="currentPassword">
</div>
</div>
<button class="btn btn-primary" type="submit">Change Password</button>
</form>

change-password.component.ts

import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators, ControlContainer, FormGroup, FormControl } from '@angular/forms';

@Component({
selector: 'app-change-password',
templateUrl: './change-password.component.html',
styleUrls: ['./change-password.component.css']
})
export class ChangePasswordComponent implements OnInit {

changePasswordForm;

constructor(formBuilder: FormBuilder) {
this.changePasswordForm = formBuilder.group({
currentPassword: new FormControl('', Validators.compose([Validators.required]))
});
}

ngOnInit() {
}

}

app.module.ts 有导入

............
imports: [
BrowserModule,
HttpModule,
FormsModule,
ReactiveFormsModule
]
...........

我收到以下错误:

Unhandled Promise rejection: Template parse errors: There is no directive with "exportAs" set to "ngModel" ("urrent Password ]#currentPassword="ngModel" id="currentPassword" name="currentPassword" type="text" class="form-co"): ChangePasswordComponent@5:4 ; Zone: ; Task: Promise.then ; Value: SyntaxError {__zone_symbol__error: Error: Template parse errors: There is no directive with "exportAs" set to "ngModel" ("urrent Passwo……} Error: Template parse errors: There is no directive with "exportAs" set to "ngModel" ("urrent Password ]#currentPassword="ngModel" id="currentPassword" name="currentPassword" type="text" class="form-co"): ChangePasswordComponent@5:4 at SyntaxError.ZoneAwareError (http://localhost:4200/polyfills.bundle.js:6884:33) at SyntaxError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:64475:16) at new SyntaxError (http://localhost:4200/vendor.bundle.js:5727:16)

最佳答案

添加 import { FormsModule } from '@angular/forms';到您的 app.module.ts 并在您需要添加 FormsModule 的导入数组中。

答案已经很晚了,但如果有人在 Angular 5 中遇到问题,你需要这样做。

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

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