這篇會研讀 <aio-nav-menu> 及 <aio-select> component,就是這一區塊

template
1 | <md-sidenav [ngClass]="{'collapsed': !isSideBySide }" #sidenav class="sidenav" [opened]="isOpened" [mode]="mode" |
- 這裡的
<aio-nav-menu>有兩個,依isSideBySide變數來決定要顯示哪一個,這兩個不會同時存在,判斷的規則是根據視窗大小
1 | private sideBySideWidth = 992; |
-
nodes 的取法,請參閱這篇文章
1
2
3
4
5this.navigationService.navigationViews.subscribe(views => {
...
this.topMenuNodes = views['TopBar'] || [];
this.topMenuNarrowNodes = views['TopBarNarrow'] || this.topMenuNodes;
});
NavMenuComponent
1 | <aio-nav-item *ngFor="let node of filteredNodes" [node]="node" [selectedNodes]="currentNode?.nodes" [isWide]="isWide"> |
1 | export class NavMenuComponent { |
NavItemComponent
ngOnChanges
1 | () isWide = false; |
ngOnChanges的changes內會包含所有@Input的變數
小技巧
-
如果想要定義的型別,不確定裡面的型態會如何,可以裡用這樣子定義
1
classes: {[index: string]: boolean };
這樣定義的資料格式會是
{ 'level-1': true, collapsed: false}在 template 上面的用法,f其實還聰明的
1
[ngClass]="classes"
aio-select
-
Component 檔案位置:
src/app/shared/select -
此 Component 使用 ul 來模擬 select-option的效果
-
Version 資訊的來源
1
2
3
4
5
6
7
8
9
10// Compute the version picker list from the current version and the versions in the navigation
// map
combineLatest(
this.navigationService.versionInfo.map(versionInfo => ({title: versionInfo.raw, url: null})),
this.navigationService.navigationViews.map(views => views['docVersions']),
(currentVersion, otherVersions) => [currentVersion, ...otherVersions])
.subscribe(versions => {
this.docVersions = versions;
this.currentDocVersion = this.docVersions[0];
});- 利用
combineLatest來將兩組資料源合併成一個新的資料源
- 利用
-
onDocVersionChange會跳至所選擇的版本網址
小技巧
HostListener搭配document:event就可以監聽到全域事件constructor內所取得的ElementRef就是Component本身的 DOM