Skip to content

Commit

Permalink
fix(module:timeline): fix timeline check error (#5245)
Browse files Browse the repository at this point in the history
close #5230
  • Loading branch information
Yadong Xie committed May 10, 2020
1 parent 1b0c3ef commit ee2859f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/timeline/public-api.ts
Expand Up @@ -9,3 +9,4 @@
export * from './timeline-item.component';
export * from './timeline.component';
export * from './timeline.module';
export * from './timeline.service';
4 changes: 3 additions & 1 deletion components/timeline/timeline-item.component.ts
Expand Up @@ -19,6 +19,7 @@ import {
} from '@angular/core';

import { NzTimelineMode } from './timeline.component';
import { TimelineService } from './timeline.service';

const TimelineTimeDefaultColors = ['red', 'blue', 'green', 'grey', 'gray'] as const;
export type NzTimelineItemColor = typeof TimelineTimeDefaultColors[number];
Expand Down Expand Up @@ -70,9 +71,10 @@ export class NzTimelineItemComponent implements OnChanges {
borderColor: string | null = null;
position: NzTimelineMode | undefined;

constructor(private cdr: ChangeDetectorRef) {}
constructor(private cdr: ChangeDetectorRef, private timelineService: TimelineService) {}

ngOnChanges(changes: SimpleChanges): void {
this.timelineService.markForCheck();
if (changes.nzColor) {
this.updateCustomColor();
}
Expand Down
12 changes: 10 additions & 2 deletions components/timeline/timeline.component.ts
Expand Up @@ -15,6 +15,7 @@ import {
Input,
OnChanges,
OnDestroy,
OnInit,
QueryList,
SimpleChange,
SimpleChanges,
Expand All @@ -25,6 +26,7 @@ import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { NzTimelineItemComponent } from './timeline-item.component';
import { TimelineService } from './timeline.service';

const TimelineModes = ['left', 'alternate', 'right'] as const;
export type NzTimelineMode = typeof TimelineModes[number];
Expand All @@ -34,6 +36,7 @@ export type NzTimelineMode = typeof TimelineModes[number];
encapsulation: ViewEncapsulation.None,
preserveWhitespaces: false,
selector: 'nz-timeline',
providers: [TimelineService],
exportAs: 'nzTimeline',
template: `
<ul
Expand Down Expand Up @@ -70,7 +73,7 @@ export type NzTimelineMode = typeof TimelineModes[number];
<ng-content></ng-content>
`
})
export class NzTimelineComponent implements AfterContentInit, OnChanges, OnDestroy {
export class NzTimelineComponent implements AfterContentInit, OnChanges, OnDestroy, OnInit {
@ContentChildren(NzTimelineItemComponent) listOfItems!: QueryList<NzTimelineItemComponent>;

@Input() nzMode?: NzTimelineMode;
Expand All @@ -83,7 +86,7 @@ export class NzTimelineComponent implements AfterContentInit, OnChanges, OnDestr

private destroy$ = new Subject<void>();

constructor(private cdr: ChangeDetectorRef) {}
constructor(private cdr: ChangeDetectorRef, private timelineService: TimelineService) {}

ngOnChanges(changes: SimpleChanges): void {
const { nzMode, nzReverse, nzPending } = changes;
Expand All @@ -96,6 +99,11 @@ export class NzTimelineComponent implements AfterContentInit, OnChanges, OnDestr
this.isPendingBoolean = nzPending.currentValue === true;
}
}
ngOnInit(): void {
this.timelineService.check$.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.cdr.markForCheck();
});
}

ngAfterContentInit(): void {
this.updateChildren();
Expand Down
15 changes: 15 additions & 0 deletions components/timeline/timeline.service.ts
@@ -0,0 +1,15 @@
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
import { ReplaySubject } from 'rxjs';

export class TimelineService {
check$ = new ReplaySubject(1);
markForCheck(): void {
this.check$.next();
}
}

0 comments on commit ee2859f

Please sign in to comment.