Skip to content

Commit df9f3e5

Browse files
cipchkvthinkxie
authored andcommitted
fix(module:upload): remove unnecessary checks (#1039)
close #1038
1 parent 6035c27 commit df9f3e5

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/components/upload/nz-upload.component.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
360360
onRemove = (file: UploadFile): void => {
361361
this.upload.abort(file);
362362
file.status = 'removed';
363-
(this.nzRemove ? this.nzRemove instanceof Observable ? this.nzRemove : of(this.nzRemove(file)) : of(true))
363+
((this.nzRemove ? this.nzRemove instanceof Observable ? this.nzRemove : of(this.nzRemove(file)) : of(true)) as Observable<any>)
364364
.pipe(filter((res: boolean) => res))
365365
.subscribe(res => {
366366
const removedFileList = this.removeFileItem(file, this.nzFileList);
@@ -411,13 +411,7 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
411411
}
412412

413413
ngOnChanges(changes: { [P in keyof this]?: SimpleChange } & SimpleChanges): void {
414-
if (changes.nzFileList) {
415-
(this.nzFileList || []).forEach(file => file.message = this.genErr(file));
416-
if (!changes.nzFileList.firstChange) return;
417-
}
418-
if (this.inited) {
419-
if (changes.nzPreview || changes.nzCustomRequest || changes.nzBeforeUpload || changes.nzRemove) return;
420-
}
414+
if (changes.nzFileList) (this.nzFileList || []).forEach(file => file.message = this.genErr(file));
421415
this.zipOptions()._setClassMap();
422416
}
423417

src/components/upload/nz-upload.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,30 @@ describe('NzUpload', () => {
2525
it('should create an instance', () => {
2626
expect(instance).toBeTruthy();
2727
});
28+
29+
it('recreate bug https://github.com/NG-ZORRO/ng-zorro-antd/issues/1038', () => {
30+
expect(instance.ref._btnOptions.disabled).toBe(false);
31+
instance.fileList = [{
32+
uid: -1,
33+
name: 'xxx.png',
34+
status: 'done',
35+
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
36+
}];
37+
fixture.detectChanges();
38+
expect(instance.ref._btnOptions.disabled).toBe(true);
39+
});
2840
});
2941

3042
@Component({
31-
template: `<nz-upload #ref [nzShowUploadList]="false">Upload</nz-upload>`
43+
template: `<nz-upload #ref
44+
[(nzFileList)]="fileList"
45+
[nzDisabled]="fileList.length >= 1"
46+
[nzShowUploadList]="false">Upload</nz-upload>`
3247
})
3348
class TestComponent {
3449

3550
@ViewChild('ref') ref: NzUploadComponent;
3651

52+
fileList = [];
53+
3754
}

0 commit comments

Comments
 (0)