Combo (コンボ) テンプレート
Ignite UI for Angular Combo のテンプレートは、Combo の各領域 (項目、グループ ヘッダー、リストのヘッダーとフッター、空のリスト、トグル アイコンとクリア アイコン、入力フィールド) の既定のコンテンツを置き換えます。
Angular の Combo は、igx-combo 要素内に配置した ng-template 要素で各テンプレートを受け取ります。ng-template 要素には、Combo のテンプレート ディレクティブのいずれかを指定します。Combo トピックに示すように、これらのディレクティブは、入力フィールドをテンプレート化する igxLabel、igx-prefix、igx-suffix、igx-hint 要素とともに IGX_COMBO_DIRECTIVES トークンに含まれています。
ライブ デモ
このサンプルでは、都市を地域別にグループ化した Destinations Combo を示します。各スイッチは Combo にテンプレートを 1 つずつ適用し、Combo の下の Selection リストには選択された都市が表示されます。
タイプ
Angular の Combo には、描画する各領域のテンプレートがあります。各テンプレートはそのディレクティブで参照し、テンプレート コンテキストから Combo の項目とキーを読み取ります。
スニペットでは、id、name、country、countryCode、region、UTC の offset を持つ目的地のデータに Combo をバインドします。valueKey は id、displayKey は name、groupKey は region です。
Item Template (項目テンプレート)
項目テンプレートは、リスト内の各オプションのコンテンツを描画します。既定では、オプションは displayKey の値を表示し、オプションのチェックボックスはテンプレートのコンテンツの前に残ります。
igxComboItem ディレクティブを使用します。テンプレートは、項目を暗黙の値として受け取り、Combo の valueKey、displayKey、data も受け取ります:
<igx-combo [data]="destinations" valueKey="id" displayKey="name" groupKey="region">
<ng-template igxComboItem let-destination let-key="displayKey">
<span class="destination">
<img class="flag" [src]="'https://dl.infragistics.com/x/img/flags/' + destination.countryCode + '.png'" alt="" />
{{ destination[key] }} — {{ destination.country }} · {{ destination.id }} · {{ destination.offset }}
</span>
</ng-template>
</igx-combo>
Header Item Template (ヘッダー項目テンプレート)
ヘッダー項目テンプレートは、Combo に groupKey が設定されている場合に、各グループのヘッダーを描画します。既定では、グループ ヘッダーにグループの値が表示されます。テンプレートが受け取るのはデータ項目ではなくヘッダー レコードで、その groupKey フィールドにグループの値が入ります。そのため、グループ内のオプション数は、スニペットの citiesIn メソッドのように Combo のデータから取得します。
igxComboHeaderItem ディレクティブを使用します。テンプレートは、ヘッダー レコードを暗黙の値として受け取り、Combo の groupKey、valueKey、displayKey、data も受け取ります:
<igx-combo [data]="destinations" valueKey="id" displayKey="name" groupKey="region">
<ng-template igxComboHeaderItem let-header let-key="groupKey">
<span class="region">
<strong>{{ header[key] }}</strong>
<span class="region-count">{{ citiesIn(header[key]) }} cities</span>
</span>
</ng-template>
</igx-combo>
Header Template (ヘッダー テンプレート)
ヘッダー テンプレートは、検索入力とオプションのリストの間に、リストのタイトルやリストに適用するアクションなどのコンテンツを描画します。Combo は既定ではヘッダーを描画しません。
igxComboHeader ディレクティブを使用します。このスニペットでは、selectAllItems メソッドで、検索入力によって絞り込まれて表示されているオプションを選択するボタンを追加します:
<igx-combo #combo [data]="destinations" valueKey="id" displayKey="name" groupKey="region">
<ng-template igxComboHeader>
<div class="list-header">
<span>Destinations by region</span>
<button igxButton="flat" (click)="combo.selectAllItems()">Select all</button>
</div>
</ng-template>
</igx-combo>
Footer Template (フッター テンプレート)
フッター テンプレートは、オプションのリストの下に、選択の概要や選択に適用するアクションなどのコンテンツを描画します。Combo は既定ではフッターを描画しません。
igxComboFooter ディレクティブを使用します。このスニペットでは、selection プロパティから選択された項目数を表示し、deselectAllItems メソッドで選択をクリアします:
<igx-combo #combo [data]="destinations" valueKey="id" displayKey="name" groupKey="region">
<ng-template igxComboFooter>
<div class="list-footer">
<span>{{ combo.selection.length }} selected</span>
<button igxButton="flat" (click)="combo.deselectAllItems()">Clear</button>
</div>
</ng-template>
</igx-combo>
Empty Template (空のリスト テンプレート)
空のリスト テンプレートは、検索テキストに一致するオプションがない場合、または Combo にデータがない場合に、リストの代わりに描画されます。既定では、Combo はリストが空であることを示すメッセージを表示します。
igxComboEmpty ディレクティブを使用します。テンプレートにコンテキストはないため、テンプレート参照を介して、Combo の searchValue プロパティから検索テキストを読み取ります。allowCustomValues が設定されている場合、追加項目は空のコンテンツの下に残ります:
<igx-combo #combo [data]="destinations" valueKey="id" displayKey="name" [allowCustomValues]="true">
<ng-template igxComboEmpty>
<span class="empty-list">No city matches "{{ combo.searchValue }}". Add it below, or try another spelling.</span>
</ng-template>
</igx-combo>
Add Template (追加テンプレート)
追加テンプレートは、allowCustomValues が設定され、検索テキストに一致するオプションがない場合に、Angular の Combo が空のリスト コンテンツの下に表示する追加項目を描画します。既定では、追加項目は “Add item” というラベルのボタンです。追加項目をクリックするか、追加項目で Enter キーを押すと、キャンセル可能な addition イベントが発生し、valueKey フィールドと displayKey フィールドに検索テキストを持つ項目が追加されて選択されます。
igxComboAddItem ディレクティブを使用し、テンプレート参照を介して searchValue プロパティから検索テキストを読み取ります:
<igx-combo #combo [data]="destinations" valueKey="id" displayKey="name" [allowCustomValues]="true">
<ng-template igxComboAddItem>
<button igxButton="outlined">Add "{{ combo.searchValue }}" as a destination</button>
</ng-template>
</igx-combo>
Toggle Icon Template (トグル アイコン テンプレート)
トグル アイコン テンプレートは、入力フィールド内のトグル ボタン (ドロップダウンを開閉するボタン) のアイコンを置き換えます。
igxComboToggleIcon ディレクティブを使用します。テンプレートは、ドロップダウンが折りたたまれているかどうかも暗黙の値として受け取るため、状態に応じて変化するアイコンを作成できます。Icon トピックに示すように、最初にアイコンを登録してください:
<igx-combo [data]="destinations" valueKey="id" displayKey="name">
<ng-template igxComboToggleIcon>
<igx-icon family="material" name="flight"></igx-icon>
</ng-template>
</igx-combo>
Clear Icon Template (クリア アイコン テンプレート)
クリア アイコン テンプレートは、入力フィールド内のクリア ボタンのアイコンを置き換えます。Combo は、項目が選択されている場合にのみクリア ボタンを表示します。
igxComboClearIcon ディレクティブを使用します:
<igx-combo [data]="destinations" valueKey="id" displayKey="name">
<ng-template igxComboClearIcon>
<igx-icon>close</igx-icon>
</ng-template>
</igx-combo>
Templated Input (テンプレート化された入力)
Combo の入力フィールドは、Input Group と同様に、ラベル、テキストの前後のコンテンツ、およびその下のヘルパー テキストを受け取ります。
ラベルは igxLabel ディレクティブで、テキストの前後のコンテンツは igx-prefix 要素と igx-suffix 要素で、ヘルパー テキストは igx-hint 要素で追加します。サフィックスのコンテンツは、クリア ボタンとトグル ボタンの前に描画されます:
<igx-combo #combo [data]="destinations" valueKey="id" displayKey="name" placeholder="Pick one or more cities">
<label igxLabel>Destinations</label>
<igx-prefix><igx-icon>place</igx-icon></igx-prefix>
<igx-suffix><igx-badge [value]="combo.selection.length"></igx-badge></igx-suffix>
<igx-hint>{{ combo.selection.length }} of {{ destinations.length }} destinations selected</igx-hint>
</igx-combo>
API リファレンス
Angular Combo の API リファレンスには、対象プラットフォームの完全な API が記載されています。
その他のリソース
次のリソースでは、Angular Combo に関するその他のガイダンスとプロジェクトのサポートを提供します: