我从Visual Studio中的Angular2组件服务调用Web API,但我不断收到错误“
JSON.parse()中位置0的JSON中的意外标记<”. ComponentService:
import { Injectable } from '@angular/core'; import {Http,Response } from '@angular/http'; import { IData } from '../Common/details'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; @Injectable() export class AniversaryService { constructor(private _http:Http) { } getImages(): Observable<IData[]> { return this._http.get("/api/ImageService/Details") .map((response: Response) => <IData[]>response.json() }; }
和相应的组件是:
import { Component,OnInit } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { IData } from '../Common/details'; import { AniversaryService } from './Aniversary.service'; @Component({ selector: 'my-AniversaryComponent',providers: [AniversaryService] }) export class AniversaryComponent implements OnInit { data: IData[]; constructor(private _aniversaryservice: AniversaryService) { } ngOnInit() { this._aniversaryservice.getImages().subscribe((details) => this.data =details); } } }
这些是网络标头和我的响应的图像(响应是在Javascript中):
有时我的状态代码显示200 ok和内容类型(在响应标题中):application / javascript
请帮我解决这个问题.
我在这里先向您的帮助表示感谢