抱歉这个问题。这与我的子组件之一有关,该组件在写入表单时拒绝空字符串。
我有一个表单控制订单号。当我尝试这样做时,
this.myForm.controls['orderNo'].setValue = '123';
它工作正常,并且我的视图已使用此值更新。
但问题是,我无法使用 null 或空字符串设置控件。每当我这样做
this.myForm.controls['orderNo'].setValue = null;
或
this.myForm.controls['orderNo'].setValue = '';
没有反映我的观点时。但是我可以看到表单控件包含该空值。(ng.probe($0).componentInstance.myForm.controls['orderNo'].value 返回 null)。它只是没有反映在视图中。
请帮助我一些想法。谢谢你。
我有一个单元测试如下
it('billing information is correct', () => {
fixture.detectChanges();
spyOn(component.myEventEmitter, 'emit').and.callThrough();
component.form.controls['size'].setValue(12);
fixture.detectChanges();
**let args= component.myEventEmitter.emit.mostRecentCall **
expect(args.billingSize).toEqual('30')
});
Run Code Online (Sandbox Code Playgroud)
当大小发生变化时,myEventEmitter 会与一个包含 billingSize 的大型 json 对象一起发出。我希望测试检查这个值是否符合预期。但看起来我无法在事件发射器上执行“mostRecentCall/calls”。有什么建议??
注意:我不想做
expect(component.myEventEmitter.emit).toHaveBeenCalledWith(*dataExpected*);
Run Code Online (Sandbox Code Playgroud)
因为 dataExpected 是一个很大的 json 对象。我只关心一个领域。任何帮助将非常感激。