Angular 5-无法绑定到"ngFormOptions",因为它不是"form"的已知属性 [英] Angular 5 - Can't bind to 'ngFormOptions' since it isn't a known property of 'form'
问题描述
我们最近将应用程序Angular版本更新为v5
,并且作为新更新的一部分,表单支持ngFormOptions
来配置对某些事件中form elements
的验证.以下是我们所做的:
We just recently updated our application Angular version to v5
and as part of new update Forms support ngFormOptions
to configure the validations for form elements
on certain events. Below is what we have done:
<form class="example-form" autocomplete="off" [ngFormOptions]="{updateOn:'submit'}" [formGroup]="testform">
</form>
但是它低于错误
无法绑定到"ngFormOptions",因为它不是的已知属性 表格"
Can't bind to 'ngFormOptions' since it isn't a known property of 'form'
更新后,应用程序的依赖关系如下.
Below the dependencies for the application after update.
package.json
package.json
"dependencies": {
"@angular/animations": "5.0.0-rc.5",
"@angular/common": "5.0.0-rc.5",
"@angular/compiler": "5.0.0-rc.5",
"@angular/core": "5.0.0-rc.5",
"@angular/forms": "5.0.0-rc.5",
"@angular/http": "5.0.0-rc.5",
"@angular/platform-browser": "5.0.0-rc.5",
"@angular/platform-browser-dynamic": "5.0.0-rc.5",
"@angular/router": "5.0.0-rc.5",
"core-js": "^2.4.1",
"ng2-accordion": "0.0.15",
"ngx-bootstrap": "^1.9.3",
"ngx-popover": "0.0.16",
"rxjs": "^5.5.2",
"typescript": "2.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.5.4",
"@angular/compiler-cli": "5.0.0",
"@angular/language-service": "5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.1.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.3.2"
}
我们在这里还想念什么?为什么即使进行了适当的更新,我们仍然会收到此错误?
What else are we missing here? Why we still get this error even after the proper update?
推荐答案
正如@Andriy在其评论中提到
As @Andriy mentioned in his comments
ngForms
选择器是selector: 'form:not([ngNoForm]):not([formGroup]),ngForm,[ngForm]'
- 源 .因此,在form
上使用formGroup
指令会将form
设置为否ngForm
,并且ngFormOptions
在这种情况下将不起作用.
ngForms
selector isselector: 'form:not([ngNoForm]):not([formGroup]),ngForm,[ngForm]'
- source . Thus, usingformGroup
directive onform
will make thisform
as NOTngForm
andngFormOptions
will have no affect in this case.
或者,我们可以在`component file中使用上述选项,如下所示:
Alternatively, we can use the said options in `component file as below:
this.testform = new FormGroup({
testcontrol: new FormControl('', Validators.required)
}, {updateOn: 'submit'});
这篇关于Angular 5-无法绑定到"ngFormOptions",因为它不是"form"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!