Скажем, у меня есть это:
isMatchedCountLessThanTotalCountMessage(){
// I want to implement this
// "returns" a string asynchronously
}
getMatchedEventsCount() {
return this.dcs.matchCount.asObservable();
}
getTotalEventsCount() {
return this.dcs.totalCount.asObservable();
}
matchedCount и totalCount выглядят так:
public matchCount = new BehaviorSubject<number>(0);
public totalCount = new BehaviorSubject<number>(0);
эти Observables запускают целые числа при изменении значений. Каждый раз, когда значение запускается из любого из них, я хочу сравнить два самых последних значения из обоих, как мне это сделать?
Я хочу вернуть логическое значение из метода
поэтому я могу отобразить в HTML:
<div>{{(isMatchedCountLessThanTotalCountMessage() | async)}}</div>
Я думаю, что Observable.zip может помочь:
isMatchedCountLessThanTotalCountMessage(){
return Observable.zip(
this.getMatchedEventsCount(),
this.getTotalEventsCount()
)
.subscribe(function(v){
const intA = v[0];
const intB = v[1];
if(intA > intB)
// but I don't know how to send a message the HTML from here
});
}