我们刚刚将应用程序的角度版本更新为v5,作为新的更新表单的一部分,我们支持ngFormOptions在某些事件上配置form elements的验证。以下是我们所做的:

<form class="example-form" autocomplete="off" [ngFormOptions]="{updateOn:'submit'}" [formGroup]="testform">

</form>

但这是个错误
无法绑定到“ngformoptions”,因为它不是
“形式”
下面是更新后应用程序的依赖项。
包装袋
"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"
}

我们还缺什么?为什么即使在正确的更新之后我们仍然会得到这个错误?

最佳答案

正如@andriy在评论中提到的
ngForms选择器是selector: 'form:not([ngNoForm]):not([formGroup]),ngForm,[ngForm]'-source。因此,在formGroup上使用form指令将使此formngForm并且在这种情况下ngFormOptions不会有任何影响。
或者,我们可以使用“组件文件”中的上述选项,如下所示:

this.testform = new FormGroup({
      testcontrol: new FormControl('', Validators.required)
}, {updateOn: 'submit'});

08-19 08:22