Hi I am trying to write a unit test using the TestComponentBuilder for an angular 2 app. When I call fixture.detectChanges() I get a no value accessor for 'settingName' error. Anybody have an idea why this would happen?
Here is a repo to see the error. It uses angular-cli https://github.com/bluefalcon/angular2-model-form-spec
here is the error: ORIGINAL EXCEPTION: No value accessor for 'settingName' ORIGINAL STACKTRACE: Error: No value accessor for 'settingName' at new BaseException (http://localhost:9876/base/dist/vendor/@angular/forms/src/facade/exceptions.js:27:23) at _throwError (http://localhost:9876/base/dist/vendor/@angular/forms/src/directives/shared.js:55:11) at Object.setUpControl (http://localhost:9876/base/dist/vendor/@angular/forms/src/directives/shared.js:30:9) at FormGroupDirective.addControl (http://localhost:9876/base/dist/vendor/@angular/forms/src/directives/reactive_directives/form_group_directive.js:71:18) at FormControlName.ngOnChanges (http://localhost:9876/base/dist/vendor/@angular/forms/src/directives/reactive_directives/form_control_name.js:39:32) at DebugAppView._View_SettingComponent0.detectChangesInternal (SettingComponent.template.js:198:55) at DebugAppView.AppView.detectChanges (http://localhost:9876/base/dist/vendor/@angular/core/src/linker/view.js:243:14) at DebugAppView.detectChanges (http://localhost:9876/base/dist/vendor/@angular/core/src/linker/view.js:348:44) at DebugAppView.AppView.detectViewChildrenChanges (http://localhost:9876/base/dist/vendor/@angular/core/src/linker/view.js:269:19) at DebugAppView._View_SettingComponent_Host0.detectChangesInternal (SettingComponent.template.js:37:8) at DebugAppView.AppView.detectChanges (http://localhost:9876/base/dist/vendor/@angular/core/src/linker/view.js:243:14) at DebugAppView.detectChanges (http://localhost:9876/base/dist/vendor/@angular/core/src/linker/view.js:348:44) at ViewRef_.detectChanges (http://localhost:9876/base/dist/vendor/@angular/core/src/linker/view_ref.js:131:65) at ComponentFixture._tick (http://localhost:9876/base/dist/vendor/@angular/core/testing/component_fixture.js:63:32) at eval (http://localhost:9876/base/dist/vendor/@angular/core/testing/component_fixture.js:77:49) at ZoneDelegate.invoke (http://localhost:9876/base/dist/vendor/zone.js/dist/zone.js?8b9c8d0a7e549abe9edec8da5a095f206d206277:323:29) at AsyncTestZoneSpec.onInvoke (http://localhost:9876/base/dist/vendor/zone.js/dist/async-test.js?8f51e44ce2093ec5167bc06760f15344db17d094:76:44) at ZoneDelegate.invoke (http://localhost:9876/base/dist/vendor/zone.js/dist/zone.js?8b9c8d0a7e549abe9edec8da5a095f206d206277:322:35) at Object.onInvoke (http://localhost:9876/base/dist/vendor/@angular/core/src/zone/ng_zone_impl.js:53:41) at ZoneDelegate.invoke (http://localhost:9876/base/dist/vendor/zone.js/dist/zone.js?8b9c8d0a7e549abe9edec8da5a095f206d206277:322:35) at Zone.run (http://localhost:9876/base/dist/vendor/zone.js/dist/zone.js?8b9c8d0a7e549abe9edec8da5a095f206d206277:216:44) at NgZoneImpl.runInner (http://localhost:9876/base/dist/vendor/@angular/core/src/zone/ng_zone_impl.js:84:71) at NgZone.run (http://localhost:9876/base/dist/vendor/@angular/core/src/zone/ng_zone.js:235:66) at ComponentFixture.detectChanges (http://localhost:9876/base/dist/vendor/@angular/core/testing/component_fixture.js:77:25) at eval (http://localhost:9876/base/dist/app/setting/setting.component.spec.js:31:29) at F (http://localhost:9876/base/dist/vendor/systemjs/dist/system-polyfills.js?a9f0c97e865a53da4c067b98cf2e65a23b2f0608:4:7484) at H (http://localhost:9876/base/dist/vendor/systemjs/dist/system-polyfills.js?a9f0c97e865a53da4c067b98cf2e65a23b2f0608:4:7116) at q.when (http://localhost:9876/base/dist/vendor/systemjs/dist/system-polyfills.js?a9f0c97e865a53da4c067b98cf2e65a23b2f0608:4:10790) at b.run (http://localhost:9876/base/dist/vendor/systemjs/dist/system-polyfills.js?a9f0c97e865a53da4c067b98cf2e65a23b2f0608:4:9826) at t._drain (http://localhost:9876/base/dist/vendor/systemjs/dist/system-polyfills.js?a9f0c97e865a53da4c067b98cf2e65a23b2f0608:4:1744) at drain (http://localhost:9876/base/dist/vendor/systemjs/dist/system-polyfills.js?a9f0c97e865a53da4c067b98cf2e65a23b2f0608:4:1398) at MutationObserver.e (http://localhost:9876/base/dist/vendor/systemjs/dist/system-polyfills.js?a9f0c97e865a53da4c067b98cf2e65a23b2f0608:4:3319) at ZoneDelegate.invoke (http://localhost:9876/base/dist/vendor/zone.js/dist/zone.js?8b9c8d0a7e549abe9edec8da5a095f206d206277:323:29) at Zone.runGuarded (http://localhost:9876/base/dist/vendor/zone.js/dist/zone.js?8b9c8d0a7e549abe9edec8da5a095f206d206277:230:48) at MutationObserver. (http://localhost:9876/base/dist/vendor/zone.js/dist/zone.js?8b9c8d0a7e549abe9edec8da5a095f206d206277:206:30) ERROR CONTEXT: [object Object]"
答案 0 :(得分:0)
终于明白了。当答案很简单时,我喜欢它。需要将disableDeprecatedForms()和provideForms()添加到addProviders([])。哦,是的,不要忘记'()'