【发布时间】:2016-12-22 00:19:09
【问题描述】:
我很清楚这里有这个错误:
https://github.com/angular/angular/issues/10148
其中提到需要先拨打fixture.detectChanges();,然后拨打fixture.whenStable()。
但是,当我开始嵌套元素时,每个元素都使用 ngModel 值访问器提供程序,我必须在循环中调用这两个方法。
有没有其他方法可以做到这一点?它似乎效率不高,我经常需要编辑这个函数。我可以使用递归方法来简化它以防止重复,但这不是问题。
export function bugWhenStable(fixture: ComponentFixture<any>): Promise<any> {
let def = new Promise(resolver => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
resolver();
});
});
});
});
return def;
}
我的组件做这样的事情:
<wm-comp1 [(ngModel)]="value"></wm-comp1>
我在 Comp1 中有哪些
<wm-comp2 [(ngModel)]="value"></wm-comp2>
等等
【问题讨论】:
-
我遇到了同样的问题 - 你有没有找到更好的方法?
-
@wags1999 不,仍然是同样的问题。我注意到多次运行时稳定并没有显着减慢我的测试速度......但是,它非常难看。创建 testBed 和组件是最慢的部分。
-
感谢发布这个问题,感谢大家的回答,你拯救了我的一天:)