首页 > 解决方案 > 无法解析 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)
    } 
    );
  }

标签: angular

解决方案


推荐阅读