久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='Vbf9W'><style id='Vbf9W'><dir id='Vbf9W'><q id='Vbf9W'></q></dir></style></legend>

    <small id='Vbf9W'></small><noframes id='Vbf9W'>

    1. <tfoot id='Vbf9W'></tfoot>
      <i id='Vbf9W'><tr id='Vbf9W'><dt id='Vbf9W'><q id='Vbf9W'><span id='Vbf9W'><b id='Vbf9W'><form id='Vbf9W'><ins id='Vbf9W'></ins><ul id='Vbf9W'></ul><sub id='Vbf9W'></sub></form><legend id='Vbf9W'></legend><bdo id='Vbf9W'><pre id='Vbf9W'><center id='Vbf9W'></center></pre></bdo></b><th id='Vbf9W'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Vbf9W'><tfoot id='Vbf9W'></tfoot><dl id='Vbf9W'><fieldset id='Vbf9W'></fieldset></dl></div>
      • <bdo id='Vbf9W'></bdo><ul id='Vbf9W'></ul>

      如何在 Ionic 中使用 CORS 編寫 Angular 2 服務?

      How do I write an Angular 2 service with CORS in Ionic?(如何在 Ionic 中使用 CORS 編寫 Angular 2 服務?)
      <i id='JN3jB'><tr id='JN3jB'><dt id='JN3jB'><q id='JN3jB'><span id='JN3jB'><b id='JN3jB'><form id='JN3jB'><ins id='JN3jB'></ins><ul id='JN3jB'></ul><sub id='JN3jB'></sub></form><legend id='JN3jB'></legend><bdo id='JN3jB'><pre id='JN3jB'><center id='JN3jB'></center></pre></bdo></b><th id='JN3jB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JN3jB'><tfoot id='JN3jB'></tfoot><dl id='JN3jB'><fieldset id='JN3jB'></fieldset></dl></div>
        <tbody id='JN3jB'></tbody>

            <bdo id='JN3jB'></bdo><ul id='JN3jB'></ul>
            • <small id='JN3jB'></small><noframes id='JN3jB'>

              <tfoot id='JN3jB'></tfoot>

                <legend id='JN3jB'><style id='JN3jB'><dir id='JN3jB'><q id='JN3jB'></q></dir></style></legend>

                本文介紹了如何在 Ionic 中使用 CORS 編寫 Angular 2 服務?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我無法使用 http 將我的 Angular 1 JavaScript 服務移動到 Angular 2 TypeScript 服務以發出 CORS 請求(這是使用 Ionic 版本 2).在 Angular 1 中,我做了這樣的事情.

                I'm having trouble moving my Angular 1 JavaScript service to a Angular 2 TypeScript service using http to make a CORS request (this is using Ionic version 2). In Angular 1, I do something like this.

                angular.module('app.services',[])
                .factory('LoginService', ['$http', function($http) { 
                 var service = {};
                
                 service.isUserLoggedIn = function() {
                  var restUrl = 'http://10.10.10.25:8080/api/user/isloggedin';
                  var options = {
                   method: 'GET', url: restUrl, withCredentials: true,
                   headers: { 
                    'x-request-with': 'XMLHttpRequest', 
                    'x-access-token': 'sometoken' 
                   }
                  };
                  return $http(options);
                 };
                
                 return service;
                }])
                

                在使用 TypeScript 的 Angular 2 中,發生了很多變化(Promises/Observables).到目前為止,我的嘗試如下所示.

                In Angular 2 using TypeScript, a lot has changed (Promises/Observables). My attempt so far looks like the following.

                import { Injectable } from '@angular/core';
                import { Headers, Http, Response, RequestMethod, RequestOptionsArgs } from '@angular/http';
                import { Observable } from 'rxjs/Observable';
                
                @Injectable()
                export class LoginService {
                  constructor(private _http:Http) {
                
                  }
                
                  isLoggedIn():boolean {
                    var r:any;
                    var e:any;
                    let url = 'http://10.10.10.25:8080/api/user/isloggedin';
                    let options:RequestOptionsArgs = {
                      url: url,
                      method: RequestMethod.Get,
                      search: null,
                      headers: new Headers({
                        'Content-Type': 'application/json',
                        'X-Requested-With': 'XMLHttpRequest',
                        'x-access-token' : 'sometoken'
                      }),
                      body: null
                    };
                    this._http.get(url, options).map(this.extractData).catch(this.handleError)
                      .subscribe(
                       response => { r = <any>response; console.log(r); }, 
                       error => { e = <any>error; console.log(e); });
                    return false;
                  }
                
                  private extractData(response:Response) {
                    let body = response.json();
                    return body.data || { };
                  }
                
                  private handleError(error:any) {
                    let errMsg = (error.message) ? error.message :
                      error.status ? `${error.status} - ${error.statusText}` : 'Server error';
                    console.log('error = ' + errMsg);
                    return Observable.throw(errMsg);
                  }
                }
                

                我不再確定如何在 Angular 2 中解決我在 Angular 1 中的問題

                I am no longer sure how to address in Angular 2 what I had in Angular 1

                • withCredentials(請注意,https://angular.io/docs/js/latest/api/http/index/RequestOptionsArgs-interface.html#!#withCredentials-anchor 說 RequestOptionsArgs 應該有一個字段withCredentials 但我在 IDE Visual Studio 代碼中收到一個錯誤,提示它在界面中不存在;ionic 可能使用的是較舊的 angular 2 版本?)
                • 標頭(x-request-with 和 x-access-token)
                • 實際反應
                • withCredentials (note that https://angular.io/docs/js/latest/api/http/index/RequestOptionsArgs-interface.html#!#withCredentials-anchor says the RequestOptionsArgs should have a field withCredentials but I get an error in the IDE Visual Studio Code saying that it does not exists in the interface; ionic is probably using an older angular 2 version?)
                • headers (x-request-with and x-access-token)
                • the actual response

                我做了更多的搜索,我能夠理解如何插入標題并正確處理訂閱.但是,withCredentials 仍然是個問題.

                I did a little bit more searching, and I was able to understand how to insert headers and properly handle the subscription. However, the withCredentials is still a problem.

                我發現這個 SO 帖子 angular2 xhrfields withcredentials true 并修改了我的構造函數,如下所示.現在可以了.

                I found this SO post angular2 xhrfields withcredentials true and modified my constructor as follows. It works now.

                constructor(@Inject(Http) private _http:Http) {
                    let _build = (<any> _http)._backend._browserXHR.build;
                    (<any> _http)._backend._browserXHR.build = () => {
                      let _xhr = _build();
                      _xhr.withCredentails = true;
                      return _xhr;
                    }
                  }
                

                推薦答案

                withCredentails 的支持將出現在即將發布的 Angular2 RC2 版本中.它不是 RC1 版本的一部分...您需要稍等.

                The support of withCredentails will be present in the RC2 version of Angular2 that will be released soon. It's not part of the RC1 version... You need to wait a bit.

                使用 RC2,您將能夠直接在請求選項中使用此屬性:

                With RC2, you will be able to use this property directly in the request options:

                this.get('...', { withCredentials: true })
                

                查看這個問題了解更多詳情:

                See this question for more details:

                • Angular 2 - http get withCredentials

                這篇關于如何在 Ionic 中使用 CORS 編寫 Angular 2 服務?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 Observable)
                Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創建使用 Ionic 組件的自定義指令?)
                Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - Angular 2 amp;離子2)
                  <bdo id='QxIag'></bdo><ul id='QxIag'></ul>

                    <tbody id='QxIag'></tbody>

                    <i id='QxIag'><tr id='QxIag'><dt id='QxIag'><q id='QxIag'><span id='QxIag'><b id='QxIag'><form id='QxIag'><ins id='QxIag'></ins><ul id='QxIag'></ul><sub id='QxIag'></sub></form><legend id='QxIag'></legend><bdo id='QxIag'><pre id='QxIag'><center id='QxIag'></center></pre></bdo></b><th id='QxIag'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='QxIag'><tfoot id='QxIag'></tfoot><dl id='QxIag'><fieldset id='QxIag'></fieldset></dl></div>

                    1. <legend id='QxIag'><style id='QxIag'><dir id='QxIag'><q id='QxIag'></q></dir></style></legend>
                      • <small id='QxIag'></small><noframes id='QxIag'>

                        <tfoot id='QxIag'></tfoot>
                          主站蜘蛛池模板: 国产视频一区在线 | 免费在线日韩 | 欧美一级毛片在线播放 | 色综合久久久 | 日韩av免费看 | 天天干天天爱天天操 | 日韩精品在线播放 | 色综合天天天天做夜夜夜夜做 | 操夜夜 | 日本亚洲一区 | 国产丝袜一区二区三区免费视频 | 国产成人精品福利 | 久久国产婷婷国产香蕉 | 操操日| 日韩午夜在线播放 | 一区二区福利视频 | 综合久久综合久久 | 日本视频中文字幕 | 欧美久久不卡 | 国产成人网 | 亚洲国产精品第一区二区 | 欧洲妇女成人淫片aaa视频 | 毛片网在线观看 | 精品久久久久久久久久久久久久 | 亚洲第1页 | 中文字幕乱码一区二区三区 | 免费在线精品视频 | 亚洲中午字幕 | 爱爱视频日本 | 九九99九九精彩46 | 精品视频一二区 | 久久久涩 | 99在线免费观看视频 | 欧美黄色片 | 在线观看免费av网 | 欧美在线a | 亚洲国产成人av好男人在线观看 | 久久久久综合 | 久久99深爱久久99精品 | 国产粉嫩尤物极品99综合精品 | 日韩av在线一区二区三区 |