2
多個佈局我想爲角> = 2與不同的佈局創建UI組件(像一個datepicker)。例如:一爲NG-引導,另一個用於角材質2.一個角2 UI組件
我想在此:
<div *ngIf="template === 1"> Bootstrap </div>
<div *ngIf="template === 2"> Angular Material </div>
這不僅是一個醜陋的解決方案,但我不認爲它會起作用,因爲ng-bootstrap和material2之間會有衝突。
另一種解決方案是創建兩個不同的組件:
<my-ng-bootstrap-component> Bootstrap </my-ng-bootstrap-component>
<my-material2-component> Angular Material </my-material2-component>
但是這不是我所需要的。因爲這對組件的用戶來說會非常混亂。
任何想法?
編輯:另外,它應該共享它們之間的一些邏輯。可能繼承?
在此先感謝
聽起來也許一個[attribute指令(https://angular.io/docs/ts/latest/guide/attribute-directives.html)簡單地應用每個樣式框架可能需要的類/組件/函數。然後,這個實現將是很好的和可讀的' ui-component>'或' ui-component>'。 –
filoxo
@filoxo你可以添加一個模板到屬性指令? – Alex
不需要。將指令看作是無模板組件。但它可以用來動態創建一個可以傳回主機的組件。我見過的一個很好的例子是[Angular Material tooltip](https://github.com/angular/material2/blob/master/src/lib/tooltip/tooltip.ts)。如果這看起來太困難或不必要,上面可能只是組件上的@ @輸入。 – filoxo