【问题标题】:Angular 4 Observable not working in IE11Angular 4 Observable 在 IE11 中不起作用
【发布时间】:2017-10-27 06:14:37
【问题描述】:

检查 URL 中的参数,基于该参数调用其他服务。它在 Chrome/Mozilla/Edge 中按预期工作,但在 IE11 中没有。它不断地重定向到同一个页面。

http://localhost/oauth/?code=xxxxxx

这是我的组件代码。

ngOnInit() {
this.sub = this.route.queryParams.subscribe(params => {
  if (params['code']) {
    this.loginProcess = 'Hold tight! Authentication in progress.';
    this.authenticationService.getOADAccessToken(params['code']).subscribe(function(res){
       // some code
    });
  else {
    // redirect to login page
  }

它正在获取参数代码值,之后甚至调用 getOADAccessToken 服务调用。但在从服务调用返回之前,它属于else 部分并再次重新加载同一页面,获取参数代码并调用服务并重新加载。
服务.ts

getOADAccessToken(token): Observable<any> {
    return this.http.post(environment.API + '/getAccessTokens',
        { code: token })
        .map((response: Response) => {
            const ADResult = response.json();
            return response.json();
        });
}

它适用于除 IE10/11 之外的所有浏览器。启用 polyfill.ts 中的所有 polyfill。已启用Intl
以下是版本详情:

【问题讨论】:

  • 我正在使用移动设备,所以我不确定,但您的 if 语句缺少右括号 }
  • @Adrian haha​​,删除了其他一些行。 '}' 存在于原始代码中

标签: angular angular-cli polyfills


【解决方案1】:

你在使用 es6-shim 吗?我有几乎类似的问题,我切换到 core.js 而不是 es6-shim。如果您想尝试一下,下面是从 es6-shim 切换到 core.js 的示例。

package.json

//replace es6-shim
    "core-js": "2.5.1",

html

<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.5.1/core.min.js"></script> 

【讨论】:

  • 已经 package.json 有 "core-js": "^2.4.1" 不使用 es6-shim。
猜你喜欢
  • 2018-10-19
  • 2016-05-10
  • 2018-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-23
  • 2018-12-15
相关资源
最近更新 更多