2017-11-01 8 views
1

편집 : 문제점의 원인을 발견했습니다. 나는 현재 그것을 해결하는 방법에 대한 해결책을 찾고있다.각도 모드를 사용하는 dev 모드에서 NgForm 오류가 발생하지 않습니다. 4.4.6

참고 :이 문제는 (예를 자극하지, 및 AOT 사용하지 않는) 개발자 모드에서 일어나는

여기에서 "업데이트"솔루션을 사용하고 있습니다 :

https://stackoverflow.com/a/46324043/3164070

양식의 유효 플래그를 업데이트하지 않는 하위 구성 요소의 입력 문제를 해결합니다. 그것은 그러나, 비교적 간단한 테스트 프로젝트에서 작동 우리의 실제 프로젝트로 이동하는 경우,이 오류가 발생합니다 :

core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: No provider for NgForm! 
Error: No provider for NgForm! 
    at ZoneAwareError (http://192.168.2.34:4200/vendor.bundle.js:153804:33) 
    at injectionError (http://192.168.2.34:4200/vendor.bundle.js:1378:90) 
    at noProviderError (http://192.168.2.34:4200/vendor.bundle.js:1416:12) 
    at ReflectiveInjector_._throwOrNull (http://192.168.2.34:4200/vendor.bundle.js:2858:19) 
    at ReflectiveInjector_._getByKeyDefault (http://192.168.2.34:4200/vendor.bundle.js:2897:25) 
    at ReflectiveInjector_._getByKey (http://192.168.2.34:4200/vendor.bundle.js:2829:25) 
    at ReflectiveInjector_.get (http://192.168.2.34:4200/vendor.bundle.js:2698:21) 
    at resolveNgModuleDep (http://192.168.2.34:4200/vendor.bundle.js:9701:25) 
    at NgModuleRef_.get (http://192.168.2.34:4200/vendor.bundle.js:10771:16) 
    at resolveDep (http://192.168.2.34:4200/vendor.bundle.js:11259:45) 
    at _createProviderInstance (http://192.168.2.34:4200/vendor.bundle.js:11102:20) 
    at resolveDep (http://192.168.2.34:4200/vendor.bundle.js:11238:56) 
    at createClass (http://192.168.2.34:4200/vendor.bundle.js:11129:32) 
    at createDirectiveInstance (http://192.168.2.34:4200/vendor.bundle.js:10960:37) 
    at createViewNodes (http://192.168.2.34:4200/vendor.bundle.js:12401:53) 
    at ZoneAwareError (http://192.168.2.34:4200/vendor.bundle.js:153804:33) 
    at injectionError (http://192.168.2.34:4200/vendor.bundle.js:1378:90) 
    at noProviderError (http://192.168.2.34:4200/vendor.bundle.js:1416:12) 
    at ReflectiveInjector_._throwOrNull (http://192.168.2.34:4200/vendor.bundle.js:2858:19) 
    at ReflectiveInjector_._getByKeyDefault (http://192.168.2.34:4200/vendor.bundle.js:2897:25) 
    at ReflectiveInjector_._getByKey (http://192.168.2.34:4200/vendor.bundle.js:2829:25) 
    at ReflectiveInjector_.get (http://192.168.2.34:4200/vendor.bundle.js:2698:21) 
    at resolveNgModuleDep (http://192.168.2.34:4200/vendor.bundle.js:9701:25) 
    at NgModuleRef_.get (http://192.168.2.34:4200/vendor.bundle.js:10771:16) 
    at resolveDep (http://192.168.2.34:4200/vendor.bundle.js:11259:45) 
    at _createProviderInstance (http://192.168.2.34:4200/vendor.bundle.js:11102:20) 
    at resolveDep (http://192.168.2.34:4200/vendor.bundle.js:11238:56) 
    at createClass (http://192.168.2.34:4200/vendor.bundle.js:11129:32) 
    at createDirectiveInstance (http://192.168.2.34:4200/vendor.bundle.js:10960:37) 
    at createViewNodes (http://192.168.2.34:4200/vendor.bundle.js:12401:53) 
    at resolvePromise (http://192.168.2.34:4200/vendor.bundle.js:153599:31) [angular] 
    at resolvePromise (http://192.168.2.34:4200/vendor.bundle.js:153570:17) [angular] 
    at http://192.168.2.34:4200/vendor.bundle.js:153647:17 [angular] 
    at Object.onInvokeTask (http://192.168.2.34:4200/vendor.bundle.js:4090:33) [angular] 
    at ZoneDelegate.invokeTask (http://192.168.2.34:4200/vendor.bundle.js:153284:36) [angular] 
    at Zone.runTask (http://192.168.2.34:4200/vendor.bundle.js:153052:47) [<root> => angular] 
    at drainMicroTaskQueue (http://192.168.2.34:4200/vendor.bundle.js:153480:35) [<root>] 
    at <anonymous> [<root>] 

문제는 같은 구성 요소가 폼에없이 사용할 수 있다는 것입니다, 그래서 더있다 NgForm 용 공급자.

양식이없는 경우에 viewProviders 구성원을 동적으로 사용하는 방법이 있습니까? 부모 NgForm 제공이없는 경우

답변

1

그래, 당신이 경우에 null로 제공 할 수

export function controlContainerFactory(controlContainer?: ControlContainer) { 
    return controlContainer; 
} 

... 

viewProviders: [ 
    { 
    provide: ControlContainer, 
    useFactory: controlContainerFactory, 
    deps: [[new Optional(), NgForm]] 
      ^^^^^^^^^^ 
      should do the trick 
    } 
] 

Stackblitz example

+0

당신은 전설입니다; 감사! –