Angular 2 SyntaxError: Unexpected token < in>)

前端 未结 2 1503
长情又很酷
长情又很酷 2021-01-13 07:44

I am calling the web API from my Angular2 Component service in Visual Studio, but continuously I am getting the error \"Unexpected token < in JSON at position 0 at JS

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 08:21

    -I recreated my component service

    import { Injectable } from '@angular/core';
    import { HttpClient, HttpErrorResponse } from '@angular/common/http';
    import { Observable } from 'rxjs/Observable';
    import 'rxjs/add/observable/throw';
    import 'rxjs/add/operator/catch';
    import 'rxjs/add/operator/do';
    import { IDetails } from '../share/Details';
    
        @Injectable()
        export class AniversaryService {
            private url = 'http://localhost:60975/api/ImageService';
            constructor(private _http: HttpClient) { }
            getDetails(): Observable {
                return this._http.get(this.url)
                    .do(data => console.log(JSON.stringify(data)))
                    .catch(this.handleError);
            }
            private handleError(err: HttpErrorResponse) {
                console.log(err.message);
                return Observable.throw(err.message);
            }
        }
    

    now it's accepting the data without any error.

提交回复
热议问题