當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Response.text方法代碼示例

本文整理匯總了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;
 }
開發者ID:dotCMS,項目名稱:core-web,代碼行數:16,代碼來源:site-browser.service.ts

示例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);
}
開發者ID:ouq77,項目名稱:portfolio-web,代碼行數:16,代碼來源:wrap.error.ts

示例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;
            });
開發者ID:fensminger,項目名稱:SyncFiles,代碼行數:16,代碼來源:login.service.ts

示例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;
             }
         }
     }
 }
開發者ID:james-hu,項目名稱:rtstatistics-web-mconsole,代碼行數:24,代碼來源:abstract-api.service.ts

示例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);
  }
開發者ID:dadall,項目名稱:PeerTube,代碼行數:18,代碼來源:rest-extractor.service.ts

示例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);
  }
開發者ID:michalzeman,項目名稱:angular2-training,代碼行數:18,代碼來源:base-entity.service.ts

示例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);
    }
開發者ID:qwb0920,項目名稱:movieapp-ionic,代碼行數:19,代碼來源:base.service.ts

示例8: convertBooleanResponse

 /**
  * Convert response from text to boolean value;
  * @param res
  */
 static convertBooleanResponse(res: Response): boolean {
     return Boolean(res.text());
 }
開發者ID:howardyan93,項目名稱:NgNode,代碼行數:7,代碼來源:rpc.ts

示例9:

 this.client.getAllExperimentsWithGET().subscribe((res:Response)=>{
   this.experiments = JSON.parse(res.text())['experiments'];
   this.filteredExperiments = this.experiments;
 },(err)=>{
開發者ID:CodingInfinity,項目名稱:Benchmark-Web-Interface,代碼行數:4,代碼來源:view.all.experiment.component.ts

示例10: convertStringResponse

 /**
  * Convert string to string;
  * @param res
  */
 static convertStringResponse(res: Response):string {
     return res.text();
 }
開發者ID:howardyan93,項目名稱:NgNode,代碼行數:7,代碼來源:rpc.ts


注:本文中的@angular/http.Response.text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。