में परिभाषित हमको संशोधित करने के एक घटक TestBed.overrideComponent
TestBed.overrideComponent(CoolComponent, {
set: {
template: '<div id="fake-component">i am the fake component</div>',
selector: 'our-cool-component',
inputs: [ 'model' ]
}
})
उपयोग कर रहे हैं एक घटक ओवरराइड करने के लिए।
घटक एक ViewChild जो हम अपने ngOnInit विधि
@Component({
selector: 'our-cool-component',
templateUrl: 'cool.component.html'
})
export class CoolComponent implements OnInit, OnDestroy {
@Input() model: SomeModel
@ViewChild(CoolChildComponent) coolChildComponent;
ngOnInit() {
this.coolChildComponent.doStuff();
}
}
CoolComponent
बारी में एक Wrapper
घटक में रहती है में कॉन्फ़िगर है।
जब हम Wrapper
स्थिरता पर fixture.detectChanges()
कहते हैं, इस CoolComponent का निर्माण करने का प्रयास करता है, लेकिन यह तुरंत मर जाता है जब यह doStuff() कहता है क्योंकि CoolChildComponent
अनिर्धारित रहता है।
क्या पर अपने CoolChildComponent
को रोकने के लिए कोई तरीका है? ऐसा प्रतीत नहीं होता है कि हम इसे Wrapper
से निकाल सकते हैं क्योंकि यह केवल टेम्पलेट के माध्यम से संदर्भित है, घटक की संपत्ति के रूप में नहीं।
मैं सिर्फ एक इनाम, जाहिरा तौर पर आपको सूचित नहीं कर रहे हैं (http://meta.stackoverflow.com/q/333838/3001761) – jonrsharpe
यह कभी काम कर रहा है जोड़ा? क्या यह ब्राउज़र में चलाए जाने पर काम करता है (या जो भी आप लक्षित कर रहे हैं)? क्या यह एक परीक्षण केवल समस्या है? – j2L4e