import { Injectable } import { Injectable },angular,compilation,try-catch"/>
import { Injectable },angular,compilation,try-catch"/>
首页 > 解决方案 > “可观察”类型上不存在“捕获”' import { Injectable } angular - “可观察”类型上不存在“捕获”' import { Injectable } 问题描述 import { Injectable } from '@angular/core'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { catchError } from 'rxjs/operators'; import { Observable, throwError } from 'rxjs'; import { AppError } from './../common/app-error'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; @Injectable({ providedIn: 'root' }) export class PostService { private url = 'http://jsonplaceholder.typicode.com/posts'; constructor(private http:HttpClient) { } getPosts(){ return this.http.get(this.url); } createPost(post){ return this.http.post(this.url, JSON.stringify(post)); } updatePost(post){ return this.http.put(this.url + '/' + post.id, JSON.stringify(post)); } deletePost(id){ return this.http.delete(this.url + '/' + id) .catch((error:Response)=>{ return Observable.throw(new AppError(error)); }); } } here compile time error in .catch part. I just want to perform error Handeling. and use catch by importing it but it will show error. that 'catch' does not exist on type 'Observable' With a combination of position and substring functions. substring(val,position('-' in val)+1,8) To reformat in the hyphenated format, use to_char, after casting the substring to date.(The assumption is that the substring is a valid date) to_char(substring(val,position('-' in val)+1,8)::date,'yyyy-MM-dd') 标签: angularcompilationtry-catch 解决方案 使用 rxjs错误处理的错误处理函数 - catch。您的代码将如下所示: deletePost(id){ return this.http.delete(this.url + '/' + id) .pipe(catchError(err => of(new AppError(err)))) } 推荐阅读 kubernetes - Kubernetes 端点类型的生命周期javascript - Javascript,未捕获的 ReferenceError:未定义变量c# - 启用复选框以在 ASP.NET GridView 上可编辑,而无需单击编辑elasticsearch - 当查询文本为字母数字模式时,Elasticsearch 将返回所有记录asp.net - ASP.Net 2.0:提交后表单不重定向android - 无法从 firebase 检索数据(java.lang.NullPointerException:尝试调用虚拟方法 'java.lang.String)server - 尝试 ping 服务器时,我不断收到请求超时,这可能是我的错吗?android - 将 adb 输出分配给批处理脚本中的变量amazon-web-services - lambda 函数中的 Rest-API 调用失败javascript - VS Code 显示模块未找到,即使 WebPack 构建有效
import { Injectable }
import { Injectable } from '@angular/core'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { catchError } from 'rxjs/operators'; import { Observable, throwError } from 'rxjs'; import { AppError } from './../common/app-error'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; @Injectable({ providedIn: 'root' }) export class PostService { private url = 'http://jsonplaceholder.typicode.com/posts'; constructor(private http:HttpClient) { } getPosts(){ return this.http.get(this.url); } createPost(post){ return this.http.post(this.url, JSON.stringify(post)); } updatePost(post){ return this.http.put(this.url + '/' + post.id, JSON.stringify(post)); } deletePost(id){ return this.http.delete(this.url + '/' + id) .catch((error:Response)=>{ return Observable.throw(new AppError(error)); }); } }
here compile time error in .catch part. I just want to perform error Handeling. and use catch by importing it but it will show error. that 'catch' does not exist on type 'Observable'
With a combination of position and substring functions.
position
substring
substring(val,position('-' in val)+1,8)
To reformat in the hyphenated format, use to_char, after casting the substring to date.(The assumption is that the substring is a valid date)
to_char
cast
date
to_char(substring(val,position('-' in val)+1,8)::date,'yyyy-MM-dd')
标签: angularcompilationtry-catch
使用 rxjs错误处理的错误处理函数 - catch。您的代码将如下所示:
deletePost(id){ return this.http.delete(this.url + '/' + id) .pipe(catchError(err => of(new AppError(err)))) }