本文整理匯總了TypeScript中@angular/http.Response.text方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.text方法的具體用法?TypeScript Response.text怎麽用?TypeScript Response.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/http.Response
的用法示例。
在下文中一共展示了Response.text方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: extractDataFilter
private extractDataFilter(res: Response): Treeable[] {
const treeables: Treeable[] = [];
const obj = JSON.parse(res.text());
const results: any[] = obj.entity.result;
for (let i = 0; i < results.length; i++) {
const r: any = results[i];
let t: Treeable;
if (r.type === 'folder') {
t = Object.assign(new Folder(), r);
} else if (r.type === 'file_asset') {
t = Object.assign(new File(), r);
}
treeables[i] = t;
}
return treeables;
}
示例2: wrapError
export function wrapError(err: Response): Observable<WrappedError> {
let wrappedError: WrappedError;
try {
wrappedError = {
status: err.status,
content: err.json()
};
} catch (jsonError) {
wrappedError = {
status: err.status,
content: err.text() || jsonError.message
};
}
console.warn(`${wrappedError.status}: ${(wrappedError.content && JSON.stringify(wrappedError.content) || '-')}`);
return Observable.throw(wrappedError);
}
示例3: SecurityToken
.map((res:Response) => {
let securityToken:SecurityToken = new SecurityToken(
{
secretKey:res.headers.get(AppUtils.HEADER_X_SECRET),
token:res.headers.get(AppUtils.HEADER_X_TOKEN_ACCESS),
securityLevel:res.headers.get(AppUtils.HEADER_WWW_AUTHENTICATE)
}
);
localStorage.setItem(AppUtils.STORAGE_ACCOUNT_TOKEN,res.text());
localStorage.setItem(AppUtils.STORAGE_SECURITY_TOKEN,JSON.stringify(securityToken));
let account:Account = new Account(res.json());
this.sendLoginSuccess(account);
return account;
});
示例4: getBody
/**
* Get the body returned in the response
*
* @private
* @param {Response} response http response
* @returns {*} null if no body, otherwise the body as an object
*/
private getBody(response: Response): any {
this.authService.authenticated(); // a successful API response received
if (response.status === 204) {
return null;
}else {
try {
return response.json();
}catch (e) {
let text = response.text();
if (text == null || text === '') {
return null;
}else {
return text;
}
}
}
}
示例5: handleError
handleError(res: Response) {
let text = 'Server error: ';
text += res.text();
let json = '';
try {
json = res.json();
} catch (err) { ; }
const error = {
json,
text
};
console.error(error);
return Observable.throw(error);
}
示例6: handleError
protected handleError(error: Response) {
// In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message
// let errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(error); // log to console instead
let status = error.status;
switch (error.status) {
case 500:
let errMsg = error.text();
this.delegateService.emitAlert(new AlertMessage(errMsg.toString(), ALERT_TYPE_DANGER));
break;
default:
this.delegateService.emitAlert(new AlertMessage('System error', ALERT_TYPE_DANGER));
break;
}
return Observable.throw(error);
}
示例7: parseResponse
private parseResponse(res: Response) {
console.log("response", res);
let contentType = res.headers.get("Content-Type");
if (contentType.indexOf("application/json") > -1) {
return res.json();
} else if (
contentType.indexOf("application/xml") > -1 ||
contentType.indexOf("text/xml") > -1) {
var x2js = new X2JS();
var text = res.text();
var jsonObj: any = x2js.xml2js<any>(text);
jsonObj = jsonObj[Object.keys(jsonObj)[0]];
return jsonObj;
}
throw new Error("Unsupported response content type - " + contentType);
}
示例8: convertBooleanResponse
/**
* Convert response from text to boolean value;
* @param res
*/
static convertBooleanResponse(res: Response): boolean {
return Boolean(res.text());
}
示例9:
this.client.getAllExperimentsWithGET().subscribe((res:Response)=>{
this.experiments = JSON.parse(res.text())['experiments'];
this.filteredExperiments = this.experiments;
},(err)=>{
示例10: convertStringResponse
/**
* Convert string to string;
* @param res
*/
static convertStringResponse(res: Response):string {
return res.text();
}