angular - Can't resolve all parameters for DataService in D:/appangular/src/app/services/data.service.ts: (?, [object Object]) 中的错误
问题描述
当我运行ng build --prod
我得到这个错误。
数据服务.ts
import { BadInput } from './../common/bad-input';
import { AppError } from './../common/app-error';
import { Injectable } from '@angular/core';
import { NotFoundError } from '../common/not-found-error';
import { throwError } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { catchError, map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private url : string ,private http : HttpClient) { }
getAll(){
return this.http.get(this.url).
pipe(map(response => response),
catchError(
this.handleError
)
)}
create(resource){
return this.http.post(this.url,resource).
pipe(
catchError(
this.handleError
)
)}
update(resource){
return this.http.put(this.url,resource).
pipe(
catchError(
this.handleError
)
)}
delete(resource){
return this.http.delete(this.url+'/'+resource.id).
pipe(
catchError(
this.handleError
)
)}
private handleError(error : Response){
if(error.status===404){
return throwError(new NotFoundError(error));
}
if(error.status===400){
return throwError(new BadInput(error))
}
return throwError(new AppError(error))
}}
解决方案
也许你需要这个?
import { BadInput } from './../common/bad-input';
import { AppError } from './../common/app-error';
import { Injectable } from '@angular/core';
import { NotFoundError } from '../common/not-found-error';
import { throwError } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { catchError, map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private http : HttpClient) { }
getAll(url : string){
return this.http.get(url).
pipe(map(response => response),
catchError(
this.handleError
)
)}
create(url : string, resource){
return this.http.post(url,resource).
pipe(
catchError(
this.handleError
)
)}
update(url : string, resource){
return this.http.put(url,resource).
pipe(
catchError(
this.handleError
)
)}
delete(url : string, resource){
return this.http.delete(url+'/'+resource.id).
pipe(
catchError(
this.handleError
)
)}
private handleError(error : Response){
if(error.status===404){
return throwError(new NotFoundError(error));
}
if(error.status===400){
return throwError(new BadInput(error))
}
return throwError(new AppError(error))
}}
推荐阅读
- windows-terminal - 如何打开带有 4 个窗格的 Windows 终端?
- typescript - 制作自定义 SaveButton 时,如何在 handleSubmitWithRedirect 上正确输入?
- javascript - Hook 的 useState 初始值在被记忆的回调中永远不会改变
- amazon-web-services - 从 ReactJS APP 检索 AWS App Config 配置
- c++ - 连续迭代器上的 SIMD 指令
- amazon-web-services - Gitlab CI失败找不到aws命令
- django - 我的登录表单在 django 中没有验证
- json - 如何在不解析的情况下读取 Scala.js 中的 JSON?
- filtering - VHDL 中的数据类型
- multithreading - 每个内核都有自己的掩码(k0-k7)寄存器吗?