Is there a way to retrieve the value of an observable without causing it to emit again? I need this value for an ngClass expression.
I attempted to use the tap operator within the pipe to access the values in switchMap, but the value is not being logged. My intention is to utilize trueIfDefinitionsLength
for the ngClass condition.
this.definitions$.pipe(
tap(value => console.log('timer result =', value))
)
The observable is subscribed using | async
Template:
<input [ngClass]="{'input-has-results': trueIfDefinitionsLength > 0}"
[formControl]="searchInput">
<ng-container *ngIf="definitions$ | async as definitions">
<div class="format-options" *ngIf="definitions.length > 0">
<div *ngFor="let definition of definitions" class="search-result">
<div>{{definition.name}}</div>
<div>{{definition.description}}</div>
</div>
</div>
</ng-container>
Component
this.definitions$ = this.searchInput.valueChanges
.pipe(
tap(value => console.log('input')),
//startWith(''),
debounceTime(500),
//distinctUntilChanged(),
switchMap(value => this.definitionService.searchTerm(value))
);