How to access the first element of an array when using an async channel?
<nav-tabs [tabs]="(pageTabs$ | async)" [activeTab]="(pageTabs$ | async)[0]"> </nav-tabs>
I tried (pageTabs$ | async)[0], but it did not work.
(pageTabs$ | async)[0]
Found an even simpler way to do this (without creating a custom channel): add a map to the observable.
component.ts
this.activeTab$ = this.pageTabs$.map(x => x[0]);
component.html
<nav-tabs [tabs]="(pageTabs$ | async)" [activeTab]="(activeTab$ | async)"> </nav-tabs>
You need to create a custom channel that will take the first element from the array, (pageTabs$ | async)not an array.
(pageTabs$ | async)
getter :
public get activeTab$() { return this.pageTabs$.map(tabs => Array.isArray(tabs)? tabs[0]: null; }
:
[active-tab]="activeTab$ | async"
nav-tabs:
public get activeTab() { return Array.isArray(this.tabs)? tabs[0]: null; }
Source: https://habr.com/ru/post/1671541/More articles:How to build, test, and deploy with Jhipster, Docker, Gitlab, and Heroku - gitlabAngular2: multiple socket routers and socket routers inside the baby route - angularFormatting print paths in a 2d grid - pythonHow to select all rows containing values that exceed a threshold value? - pythonIs there a way to create a namespace with generic attributes? - c ++Why are fixed Eigen Matrix Library types with embedded data not PoD? - c ++Почему я не могу получить вывод хвоста файла, созданного сборкой докеров - dockerЛучше ли использовать один большой буфер со всеми связанными данными или несколькими меньшими буферами в HLSL - directxHow to connect two laravel applications? - laravelВектор подмножества: как программно передать отрицательный индекс безопасно? - rAll Articles