1. 程式人生 > >10.15 tab-control邏輯回顧

10.15 tab-control邏輯回顧

emmmmm,現在變成開發冷鏈車監控系統了,說白了就是地圖。

但是目前這個網頁的佈局地圖模組的位置太小了,想重新整改一下,研究了好久tab-control模組,涉及到元件之間互動,主要在子元件和父元件間,同等元件之間的可能要用subscribe了吧......父子元件互動有@input,@Output,@ChildView,還有各種ViewContainerRef,ElementRef,TemplateRef.....不懂不懂

整個頁面載入的順序和邏輯應該是這樣的:

登入後召喚dashboard元件,元件模板裡有header、region-panel區域、報警模組、gps模組、tab-control模組。tab-control比較特殊是在dashboard控制的

dashboard.html裡有一行<app-tab-control #tabCtrl></app-tab-control>

dashboard.ts裡有@ViewChild(‘tabCtrl)’ tabCtrl指代tab-control這個模組,dashboard有一個變數subregion,這個變數來自於它的子元件region-panel,用@Output和時間發射器傳到dashboard的。

頁面初始化後mainpanel部分是沒有顯示的,需要根據選擇的區域來顯示資料。mainpanel那一塊空著的地方要顯示tab和tab對應的mainpanel。tab顯示是根據tab-control模組的relationList,List裡有幾個就顯示幾個tab

1、使用者在regionPanel點選subregion,regionpanel將收到的區域發射給dashboard(子元件到父元件)

2、dashboard用子元件的代號tabCtrl在dashboard介面呼叫tab-control子元件的函式(父元件傳參到子元件,這裡用viewChild,好像用input也可以吧)

      a、判斷relationList裡有沒有這個subregion

  沒有:先addPanel(建立這個區域的mainPanel元件),再activePanel讓它顯示出來,具體的就是讓instance的isShow屬性變為true。

   :之間activePanel,先把所有instance的isShow改為false,再把對應的instance的改為true。

關於建立mainpanel元件,程式碼如下,用到resolveComponentFactory服務物件

const mainPanelFactory = this._resolver.resolveComponentFactory(MainPanelComponent);
const ref = this.mainPanel.createComponent(mainPanelFactory);
//呼叫resolveComponentFactory服務以mainpannelComponent類為模板建立元件

ref.instance.subregion = subregion;
//這句話非常重要,將subregion引數傳入新建立的mainpanel的例項中去。所以mainpanel的subregion是這麼來的。。