我有一个工作 Observable需要返回格式化的纯文本(不是 JSON)。当我在浏览器中拉出端点时,格式化的纯文本会正确显示。是否可以将开关添加到我的 Angular2 服务中以显示原始空格和换行符。
示例:来自我的http.service.ts文件:
import {Injectable} from 'angular2/core';
import {Http} from "angular2/http";
import {Observable} from "rxjs/Observable";
import 'rxjs/Rx';
@Injectable()
export class HttpService {
constructor(private http: Http) {}
// Endpoing must set "Access-Control-Allow-Origin" header
getPosts(): Observable<any> {
return this.http.get('http://localhost:8000') //local testing web service
.map(res => res.text().PreservePlainTextFormating());
}
我很抱歉这个例子不是一个有效的例子。我编造了.PreservePlainTextForrmating()来描述我要在代码中完成的工作。
提前感谢您的帮助。