From 0ece6123a586c96a6178e2ba939b9451c031bc14 Mon Sep 17 00:00:00 2001 From: NAN <793441489@qq.com> Date: Thu, 16 Dec 2021 17:41:13 +0800 Subject: [PATCH] fix(module:timeline): when the data clear. reset items (#7109) --- components/timeline/timeline.component.ts | 3 ++ components/timeline/timeline.spec.ts | 38 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/components/timeline/timeline.component.ts b/components/timeline/timeline.component.ts index de3d71d06c..2528fbd387 100644 --- a/components/timeline/timeline.component.ts +++ b/components/timeline/timeline.component.ts @@ -151,6 +151,9 @@ export class NzTimelineComponent implements AfterContentInit, OnChanges, OnDestr this.timelineItems = this.nzReverse ? this.listOfItems.toArray().reverse() : this.listOfItems.toArray(); this.hasLabelItem = hasLabelItem; + } else { + this.timelineItems = []; + this.hasLabelItem = false; } this.cdr.markForCheck(); diff --git a/components/timeline/timeline.spec.ts b/components/timeline/timeline.spec.ts index ac01334764..eff5ff5e96 100644 --- a/components/timeline/timeline.spec.ts +++ b/components/timeline/timeline.spec.ts @@ -245,6 +245,27 @@ describe('nz-timeline', () => { expect(timeline.nativeElement.firstElementChild!.classList).not.toContain('ant-timeline-rtl'); }); }); + + describe('clear', () => { + let testBed: ComponentBed; + let fixture: ComponentFixture; + let timeline: NzTimelineComponent; + + beforeEach(() => { + testBed = createComponentBed(NzTestTimelineClearItemsComponent, { + imports: [NzTimelineModule] + }); + fixture = testBed.fixture; + fixture.detectChanges(); + timeline = fixture.componentInstance.nzTimeLine; + }); + + it('test clear items', () => { + fixture.componentInstance.reset(); + fixture.detectChanges(); + expect(timeline.timelineItems.length).toBe(0); + }); + }); }); @Component({ @@ -314,3 +335,20 @@ export class NzTestTimelineRtlComponent { @ViewChild(Dir) dir!: Dir; direction = 'rtl'; } + +@Component({ + template: ` + + {{ item }} + + reset + ` +}) +export class NzTestTimelineClearItemsComponent { + @ViewChild(NzTimelineComponent) + nzTimeLine!: NzTimelineComponent; + data = [1, 2, 3]; + reset(): void { + this.data = []; + } +}