我正在尝试合并两个可观察值,比较两个值并根据结果输出宽度。 我正在按照https://coryrylan.com/blog/angular-multiple-http-requests-with-rxjs#forkjoin
中的步骤进行操作该错误实际上在此代码中
.subscribe( (results) => {
我也尝试过使用此代码,但是错误仍然相同
.subscribe( ([res1, res2]) => {
代码如下:
ngOnInit() {
forkJoin([this.sidenavService.lSidenavOpenSub$, this.sidenavService.rSidnavOpenSub$])
.subscribe( (results) => {
if (results[0] == false && results[1] == false) {
this.width = this.widthService.width100;
debugger;
console.log('noneOpen');
} else if (results[0] == true && results[1] == false) {
this.width = this.widthService.width100 - this.leftWidth;
debugger;
console.log('leftOpen');
} else if (results[0] == true && results[1] == true) {
this.width = this.widthService.width100 - (this.rightWidth + this.leftWidth);
debugger
console.log('bothOpen');
} else if (results[0] == false && results[1] == true) {
this.width = this.widthService.width100 - this.rightWidth;
debugger
console.log('rightOpen');
}
}
}
答案 0 :(得分:1)
subscribe
末尾缺少右括号
.subscribe( (results) => {
if (results[0] == false && results[1] == false) {
this.width = this.widthService.width100;
debugger;
console.log('noneOpen');
} else if (results[0] == true && results[1] == false) {
this.width = this.widthService.width100 - this.leftWidth;
debugger;
console.log('leftOpen');
} else if (results[0] == true && results[1] == true) {
this.width = this.widthService.width100 - (this.rightWidth + this.leftWidth);
debugger
console.log('bothOpen');
} else if (results[0] == false && results[1] == true) {
this.width = this.widthService.width100 - this.rightWidth;
debugger
console.log('rightOpen');
}
}) // here ...................