Currently, I am attempting to access Observable in the component.html file using the following code:
{{ (pins | async)[0]?.state }}
I am uncertain if this approach is valid, but I am looking to access a single part of the Observable list in HTML without utilizing *ngFor loop. (I am specifically working with Firebase.) Below is the code snippet from component.ts:
pins: Observable<any[]>;
this.pins = this.db.list('pins').snapshotChanges().pipe(
map(changes =>
changes.map(c => ({ $key: c.payload.key, ...c.payload.val() }))
)
);
Furthermore, here is the JSON data for 'pins':
[
{
"$key": "0",
"pin": 5,
"state": true
},
{
"$key": "1",
"pin": 4,
"state": false
},
...
]
The code functions correctly for the first item, however, it encounters an issue when trying to display subsequent items, resulting in the error message:
ERROR TypeError: Cannot read property '0' of null
at Object.eval [as updateRenderer] (HomeComponent.html:88)
...
Your assistance in resolving this issue would be greatly appreciated. Thank you!