angular - 无法解析 DataService 的所有参数中的错误
问题描述
我正在完成我的项目,当我运行cmd 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
)
)}
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))
}}
post.component.ts
import { BadInput } from './../common/bad-input';
import { AppError } from './../common/app-error';
import { PostService } from './../services/post.service';
import { Component, OnInit } from '@angular/core';
import { NotFoundError } from '../common/not-found-error';
@Component({
selector: 'posts',
templateUrl: './posts.component.html',
styleUrls: ['./posts.component.css']
})
export class PostsComponent implements OnInit {
posts:any[]=[];
status=true;
post={
id:0,
title:'',
body:'',
userId:''
};
constructor( private postService : PostService ) {
}
ngOnInit() {
this.getPost(
);
}
getPost(){
this.postService.getAll()
.subscribe(
(response:any[])=>{
this.posts=response;
},error=>{
alert('error innattendue')
console.log(error)
}
);
}
解决方案
推荐阅读
- vue.js - Vue + Flask Gmail API
- windows - 从 3.0 升级到 Powershell 5.1
- android - 如何在 Flutter 中将图像转换为二维码?
- amazon-web-services - AWS - 无法从另一台服务器 ping GNS3 路由器
- gstreamer - 有没有办法在 gst-launch-1.0 PIPELINE-DESCRIPTION 中创建动态管道?
- python - 如何使用 For 循环在 Python 中打印所有需要的值?
- c# - 我已经创建了一个库存系统,但我不知道如何进行
- informatica - Informatica Cloud 中的源文件结构将每天更改
- javascript - Sonarqube 未显示安全热点
- pine-script - 使用 pine-script 在我的图表上不需要的线