如何修复角度错误的“错误连接被拒绝”

时间:2019-04-07 15:34:41

标签: c# angular asp.net-web-api

我正在使用webApi和angular 7构建一个Web应用程序。 之所以使用webApi部分,是因为当我运行dotnet watch run时,它会从浏览器中的数据库中带走我的数据,但是当我用angular连接它时,我会得到错误的连接。

我检查了网址。是正确的

这是我的服务。

const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
const apiUrl = 'http://localhost:5000/api';

@Injectable({
providedIn: 'root'
})
export class ApiService {

 constructor(private http: HttpClient) { }




 private handleError<T>(operation = 'operation', result?: T) {
return (error: any): Observable<T> => {

  // TODO: send the error to remote logging infrastructure
  console.error("emptyyyyyy"); // log to console instead

  // Let the app keep running by returning an empty result.
  return of(result as T);
};
}

 getEmployees(): Observable<Employee[]> {
 return this.http.get<Employee[]>(apiUrl)
  .pipe(

    catchError(this.handleError('getSuppliers', []))
  );
  }


}

在控制台中说:emptyyy和err连接被拒绝

0 个答案:

没有答案