大佬教程收集整理的这篇文章主要介绍了Angular 2 SyntaxError:JSON.parse()中位置0的JSON中的意外标记<,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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
请帮我解决这个问题.
我在这里先向您的帮助表示感谢
以上是大佬教程为你收集整理的Angular 2 SyntaxError:JSON.parse()中位置0的JSON中的意外标记<全部内容,希望文章能够帮你解决Angular 2 SyntaxError:JSON.parse()中位置0的JSON中的意外标记<所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。