如何在运营商链中订阅之前检查条件?我有类似的东西。
onDropdownChange(event:Event)
{
this.parentElem = event.value === 'parent';
}
此函数更改属性值。
<select (change)="onDropdownChange($event)">
...
</select>
html元素
.takeWhile(...)
已经尝试使用.skipWhile(...)
&amp; #include <iostream>
class Box
{
public:
double l, w, h;
double vol, surf;
double getVol() { return l*w*h; };
double getSurf() { return (l*w + l*h + w*h) * 2; };
double getVolDiff()
{
boxTemp->l = l + 1;
boxTemp->w = w;
boxTemp->h = h;
return getVol() - boxTemp->getVol();
};
static Box* getInstance() {
if (_instance == 0) {
_instance = new Box;
}
return _instance;
}
void setTemp(Box *b1) {
boxTemp = b1;
}
private:
Box* boxTemp;
static Box *_instance;
};
Box* Box::_instance = 0;
int main(int argc, const char * argv[]) {
Box box;
box.l = 1;
box.w = 2;
box.h = 3;
std::cout << "Vol: " << box.getVol() << std::endl;
std::cout << "Surf: " << box.getSurf() << std::endl;
Box *orj = Box::getInstance();
orj->l = 4;
orj->w = 5;
orj->h = 6;
std::cout << "*** Vol: " << box.getVol() << std::endl;
std::cout << "*** Surf: " << box.getSurf() << std::endl;
orj->setTemp(&box);
std::cout << "Vol Diff: " << orj->getVolDiff() << std::endl;
return 0;
但我不知道它是否适用于我的病情。
答案 0 :(得分:1)
通过这样做解决了。
this.myForm.get('grandParent').valueChanges
.filter(() => this.parentElem && ...more conditions) // only execute further chain if true;
.map(val => {
this.$parent.empty();
return this.dropdownProvider.getParent(val);
}).subscribe(service => service.subscribe(data => {
data = data.map(d => { return { id: d.text, text: d.text }; });
this.initParent(data);
}));