<p> i have tried all these
import {Observable,EMPTY,throwError} from 'rxjs'
import 'rxjs/add/operator/catch';
//import 'rxjs/add/operator/map'
//import 'rxjs/Rx'
//import {map,catchError} from 'rxjs/operators'
import { } from "rxjs/operators";
import { map, filter, catchError, mergeMap } from 'rxjs/operators'</p>
public isLoggedIn():Observable<boolean>{
return this.http.get("https://jsonplaceholder.typicode.com/todos/1")
.pipe(map((res:Response)=> res)
.catch((error:any)=>Observable.throw(error||'Server Error')))
}
答案 0 :(得分:0)
在RxJS v6中,您列出了pipe()
内的运算符逗号分隔
catch
现在也称为catchError
尝试以下方法:
public isLoggedIn():Observable<boolean>{
return this.http.get("https://jsonplaceholder.typicode.com/todos/1").pipe(
map((res:Response)=> res),
catchError((error:any)=>Observable.throw(error||'Server Error')))
)
}
答案 1 :(得分:0)
使用 function javascript_click() {
if (document.getElementById("value3").value && document.getElementById("value4").value) {
var attName = document.getElementById("value3").value;
var attValue = document.getElementById("value4").value;
var value = "[" + attName + "=" + attValue + "]";
var num2 = document.querySelectorAll(value).length;
document.getElementById("cnt").innerHTML += "선택하신 노드는 " + num2 + "개 입니다. By javascript<br>";
} else {
document.getElementById("cnt").innerHTML += "wrong value of ID <br>";
}
}
代替 <form action="">
<table class="tg" id="tg">
<tr>
<td>Attribute name</td>
<td><input type="text" id="value3"></td>
</tr>
<tr>
<td>attribute value</td>
<td><input type="text" id="value4"></td>
</tr>
</table>
<div id="cnt"></div>
</form>
<div class="button">
<button id='btn_javascript' onclick="javascript_click();">javascript</button>
</div>
并且您必须从CatcError
函数返回一个可观察值!
修改后的代码:
catch