Angular 如何获得可观察的';s值而不触发新的发射
我怎样才能在不触发新发射的情况下获得可观测值的值?我想得到ngClass标记中的可观测值 我尝试使用pipe tap在值通过switchMap时获取值,但没有记录值。然后我可以对ngClass条件使用Angular 如何获得可观察的';s值而不触发新的发射,angular,typescript,rxjs,Angular,Typescript,Rxjs,我怎样才能在不触发新发射的情况下获得可观测值的值?我想得到ngClass标记中的可观测值 我尝试使用pipe tap在值通过switchMap时获取值,但没有记录值。然后我可以对ngClass条件使用trueIfDefinitionsLength this.definitions$.pipe( tap(value => console.log('timer result =', value)) ) 用| async订阅的可观测数据 模板: <input [ngClass]="{
trueIfDefinitionsLength
this.definitions$.pipe(
tap(value => console.log('timer result =', value))
)
用| async订阅的可观测数据
模板:
<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>
改用
行为主题。它有一个方法getValue()
来获取当前值而不发出新值。使用行为子对象。它有一个方法getValue()
来获取当前值而不发出新值。ReplaySubject
在这种情况下也可能很方便。它缓存n个lastnext
,然后为每个尚未看到它们的新订阅者重新发布它们。ReplaySubject
在这种情况下也可能很方便。它缓存n个lastnext
,然后为每个尚未看到这些内容的新订阅者重新发布这些内容。主题呢?它没有获取当前值的方法。是的,我删除了注释。。是否可以在switchMap的结果中获取组件代码中的值?definition$Behavior Subject的最新/当前值也是我要查找的。我将实现它。Subject呢?它没有获取当前值的方法。是的,我删除了注释。。有可能在switchMap的结果中获得组件代码中的值吗?definition$BehaviorSubject的最新/当前值也是我要寻找的。我将实现为什么不在Observables中使用Subject和ReplaySubject的函数?@doe,因为你应该保持简单,并负责一项明确的任务。可观察的是你可以被观察到的东西。就这样。观察者是能够观察的东西。主语是可观察的,同时也是观察者。为什么不在可观察的事物中设置主语和重放主语的功能?@doe,因为你应该保持事物的简单性,并对一项明确的任务负责。可观察的是你可以被观察到的东西。就这样。观察者是能够观察的东西。主体是可观察的,同时也是观察者。
this.definitions$ = this.searchInput.valueChanges
.pipe(
tap(value => console.log('input')),
//startWith(''),
debounceTime(500),
//distinctUntilChanged(),
switchMap(value => this.definitionService.searchTerm(value))
);