-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:tabs): support lazy load tabs (#2968)
close #2716
- Loading branch information
Showing
10 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 12 | ||
title: | ||
zh-CN: 懒加载 | ||
en-US: LazyLoad | ||
--- | ||
|
||
## zh-CN | ||
|
||
默认情况下,`nz-tab` 中的组件会进行预加载,如果希望当 Tab 被激活时再加载组件,可以使用该示例中的懒加载方式。 | ||
|
||
## en-US | ||
|
||
By default, the contents in `nz-tab` are eagerly loaded. Tab contents can be lazy loaded by declaring the body in a `ng-template` with the `[nz-tab]` attribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* entryComponents: NzDemoTabContentLazyComponent,NzDemoTabContentEagerlyComponent */ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-tabs-lazy', | ||
template: ` | ||
<nz-tabset> | ||
<nz-tab nzTitle="Tab Eagerly 1"> | ||
<nz-demo-tab-content-eagerly></nz-demo-tab-content-eagerly> | ||
</nz-tab> | ||
<nz-tab nzTitle="Tab Eagerly 2"> | ||
<nz-demo-tab-content-eagerly></nz-demo-tab-content-eagerly> | ||
</nz-tab> | ||
<nz-tab nzTitle="Tab Lazy 1"> | ||
<ng-template nz-tab> | ||
<nz-demo-tab-content-lazy></nz-demo-tab-content-lazy> | ||
</ng-template> | ||
</nz-tab> | ||
<nz-tab nzTitle="Tab Lazy 2"> | ||
<ng-template nz-tab> | ||
<nz-demo-tab-content-lazy></nz-demo-tab-content-lazy> | ||
</ng-template> | ||
</nz-tab> | ||
</nz-tabset>` | ||
}) | ||
export class NzDemoTabsLazyComponent { | ||
} | ||
|
||
@Component({ | ||
selector: 'nz-demo-tab-content-lazy', | ||
template: `lazy` | ||
}) | ||
export class NzDemoTabContentLazyComponent implements OnInit { | ||
ngOnInit(): void { | ||
console.log(`I will init when tab active`); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'nz-demo-tab-content-eagerly', | ||
template: `eagerly` | ||
}) | ||
export class NzDemoTabContentEagerlyComponent implements OnInit { | ||
ngOnInit(): void { | ||
console.log(`I will init eagerly`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { | ||
Directive | ||
} from '@angular/core'; | ||
|
||
/** Decorates the `ng-template` tags and reads out the template from it. */ | ||
@Directive({ | ||
selector: '[nz-tab]' | ||
}) | ||
export class NzTabDirective { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters