asp.net - Angular 6 - IE11 上的 GET/POST 问题 - 符号(rxSubscriber)未定义

标签 asp.net asp.net-mvc angular internet-explorer polyfills

在使用 Angular 6 的 IE11 上使用简单的 GET/POST 时,我遇到了奇怪的问题 - Symbol(rxSubscriber) 未定义。 Angular 5 上也出现同样的问题。不幸的是升级没有帮助。 这段代码在 Chrome 和 Firefox 上运行良好,但在 IE 上我收到如下错误。更有趣的是,当 ng 在 IE11 上服务和运行时,相同的代码也可以很好地工作。 Angular 在 ASP .NET MVC View 中继承,如下所示。此外,polyfills 未注释,因为它应该在 IE 上工作。应用程序是.NET WebForms/.NET MVC/Angular 的组合。有什么解决办法吗?

ERROR TypeError: Invalid calling object
   "ERROR"
   {
      [functions]: ,
      __proto__: {
         [functions]: ,
         __proto__: { },
         message: "",
         name: "TypeError",
         Symbol(rxSubscriber)_g.85rjwpn14tf: undefined
      },
      description: "Invalid calling object",
      message: "Invalid calling object",
      name: "TypeError",
      number: -2147418113,
      stack: "TypeError: Invalid calling object
   at scheduleTask (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:9279:13)
   at ZoneDelegate.prototype.scheduleTask (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:6722:21)
   at DELEGATE_ZS.onScheduleTask (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:6612:13)
   at ZoneDelegate.prototype.scheduleTask (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:6716:17)
   at Zone.prototype.scheduleTask (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:6547:17)
   at Zone.prototype.scheduleMacroTask (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:6570:13)
   at scheduleMacroTaskWithCurrentZone (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:7429:5)
   at Anonymous function (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:9316:17)
   at proto[name] (http://localhost:60646/Angular-Test/dist/Angular-Test/polyfills.js:7709:17",
      Symbol(rxSubscriber)_g.85rjwpn14tf: undefined
   }

我的代码如下所示:

Index.cshtml

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    string virtualPathDirectory = !string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("VirtualDirectoryPath")) ? System.Configuration.ConfigurationManager.AppSettings.Get("VirtualDirectoryPath") : string.Empty;
}

@section head {
    <base href="@virtualPathDirectory/" />
}
<div>
    <app-root></app-root>
</div>

@section scripts {
}

_Layout.cshtml

@using System.Text.RegularExpressions
@using System.Web.Optimization
@{ 
    string virtualPathDirectory = !string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("VirtualDirectoryPath")) ? System.Configuration.ConfigurationManager.AppSettings.Get("VirtualDirectoryPath") : string.Empty;
}
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    @RenderSection("head", required: false)
</head>
<body>
    @RenderBody()
    <script type="text/javascript" src="@virtualPathDirectory/bootstrap/js/plugins/pace/pace.min.js"></script>
    <script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/runtime.js"></script>
    <script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/polyfills.js"></script>
    <script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/main.js"></script>
    <script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/vendor.js"></script>

    @RenderSection("scripts", required: false)
</body>
</html>

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule }    from '@angular/common/http';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';
import { TestService } from './test.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(private TestService: TestService) { }

  ngOnInit() {
    this.TestService.GetUser().subscribe(user => this.User = user);
  }

  User: User = new User();
}

export class User {
  id: number;
  name: string;
  username: string;
  email: string;
  address: Address;
  phone: string;
  website: string;
  company: Company;
}

export class Address {
  street: string;
  suite: string;
  city: string;
  zipcode: string;
  geo: Geo;
}

export class Geo {
  lat: string;
  lng: string;
}

export class Company {
  name: string;
  catchPhrase: string;
  bs: string;
}

app.component.html

ID: {{ User.id }}<br />
name: {{ User.name }}<br />
username: {{ User.username }}

test.service.ts

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class TestService {

  constructor(private http: HttpClient) { }

  GetUser(): Observable<User> {
    return this.http.get<User>('https://jsonplaceholder.typicode.com/users/1').pipe();
  }
}

export class User {
  id: number;
  name: string;
  username: string;
  email: string;
  address: Address;
  phone: string;
  website: string;
  company: Company;
}

export class Address {
  street: string;
  suite: string;
  city: string;
  zipcode: string;
  geo: Geo;
}

export class Geo {
  lat: string;
  lng: string;
}

export class Company {
  name: string;
  catchPhrase: string;
  bs: string;
}

最佳答案

好的,我发现一个问题。正如我最初认为的那样,问题与 .NET WebForms/.NET MVC/Angular 组合无关。忘记了我将pace.min.js放在Angular脚本之前,这就是问题的根源。当我在 Angular 问题消失后移动这个脚本时。我通过在 IE11 上的 Angular 内部调试 zone.js 来跟踪它,并得到 IE11 控制台中发生 2 个相同错误的提示。看起来pace.js与zone.js冲突,因为所有XHR(Angular重建对XHR的GET/POST请求)都失败了。不知道为什么它在 Chrome 或 Firefox 中可以正常工作,但是如果您在 Angular 脚本之前的任何地方使用pace.js,请考虑将其移到它们之后,如下所示:

<script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/runtime.js"></script>
<script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/polyfills.js"></script>
<script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/main.js"></script>
<script type="text/javascript" src="@virtualPathDirectory/Angular-Test/dist/Angular-Test/vendor.js"></script>
<script type="text/javascript" src="@virtualPathDirectory/bootstrap/js/plugins/pace/pace.min.js"></script>

关于asp.net - Angular 6 - IE11 上的 GET/POST 问题 - 符号(rxSubscriber)未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52038123/

相关文章:

asp.net - 通过文件上传控件上传时在 c#.net 中重命名文件,并将文件的更改名称保存在数据库中

asp.net - 如何从 gridbox 中检索更新的数据并在数据库中更新它

asp.net - 如何找出我的线程在 ASP.NET 中被停止的原因?

c# - ASP.NET 框架错误

javascript - 单页分页问题中的多 Angular Material 表

javascript - Angular 2+ ngModel 仅使用对象括号表示法在嵌套值上绑定(bind)动态 ngModel 的一种方式

javascript - 使用部分 View 将点击搜索转变为即时搜索

c# - 在 ASP.NET MVC 操作中隐式声明参数

c# - .net 检查用户是否登录 signalR

angular - 在 ngrx 效果中将 Promise 转换为 Observable