【问题标题】:No provider for PlatformRef error after upgrading to Angular2 RC5 in IE10在 IE10 中升级到 Angular2 RC5 后没有提供 PlatformRef 错误
【发布时间】:2017-01-03 03:31:58
【问题描述】:

我刚刚升级到 Angular2 RC5。该应用程序在所有浏览器(IE10 除外)中都能正常加载。我得到一个例外“没有 PlatformRef 的提供者!”当我引导应用程序时。在 RC4 中一切正常。我在网上看到一些关于这个异常的帖子,但它们都与 Meteor 有关。我不使用流星。我的项目源自 AngularSeed(我手动更新到 RC5 的先前版本)。关于如何解决这个问题的任何想法?谢谢!

在 IE10 中,我收到此错误:

No provider for PlatformRef!  
{
  [functions]: ,
  context: <Permission denied>,
  injectors: [ ],
  keys: [ ],
  message: "No provider for PlatformRef!",
  name: "Error",
  stack: undefined,
  Symbol()_m.sovohbnexgu: undefined,
  Symbol()_n.sovohbnexgu: undefined,
  Symbol()_o.sovohbnexgu: undefined,
  Symbol(rxSubscriber)_p.sovohbnexgu: undefined
}

main.ts:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule }              from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

应用模块:

import { provide, NgModule, ExceptionHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './components/app/app.component';
import { AppExceptionHandler } from './app.exceptionhandler';
import { AppRoutes } from './app.routes';
import { LogService, ... } from './services/';

@NgModule({
    declarations: [AppComponent, ...],
    imports: [BrowserModule,
              RouterModule.forRoot(AppRoutes),
              HttpModule,
              FormsModule],
    providers: [provide(ExceptionHandler, { useClass: AppExceptionHandler }), LogService, ...],
    bootstrap: [AppComponent],
})
export class AppModule { }

依赖版本:

  • “@angular/common”:“2.0.0-rc.5”,
  • "@angular/compiler": "2.0.0-rc.5",
  • “@angular/core”:“2.0.0-rc.5”,
  • “@angular/forms”:“0.3.0”,
  • “@angular/http”:“2.0.0-rc.5”,
  • "@angular/platform-b​​rowser": "2.0.0-rc.5",
  • "@angular/platform-b​​rowser-dynamic": "2.0.0-rc.5",
  • "@angular/router": "3.0.0-rc.1",
  • "es6-module-loader": "^0.17.8",
  • “core-js”:“^2.4.0”,
  • “rxjs”:“5.0.0-beta.6”,
  • “systemjs”:“0.19.27”,
  • “zone.js”:“0.6.13”,

编辑:如果我尝试将 PlatformRef 添加到 @NgModule 导入,我会收到此错误:

shims.js?1472473326356:4 Uncaught TypeError: Cannot read property 'type' of null(anonymous function) 
@ app.js?1472473326358:5getTransitiveModules 
@ app.js?1472473326358:5CompileMetadataResolver._getTransitiveNgModuleMetadata 
@ app.js?1472473326358:5CompileMetadataResolver.getNgModuleMetadata 
@ app.js?1472473326358:5RuntimeCompiler._compileComponents 
@ app.js?1472473326358:3RuntimeCompiler._compileModuleAndComponents 
@ app.js?1472473326358:3RuntimeCompiler.compileModuleAsync 
@ app.js?1472473326358:3PlatformRef_._bootstrapModuleWithZone 
@ app.js?1472473326358:48PlatformRef_.bootstrapModule 
@ app.js?1472473326358:48bootstrapper 
@ app.js?1472473326358:57(anonymous function) 
[...]

我在 IE 上得到了这个堆栈:

"TypeError: Unable to get property 'type' of undefined or null reference
   at Anonymous function (eval code:13673:13)
   at Call (http://localhost:5555/node_modules/es6-shim/es6-shim.js?1472473192889:289:7)
   at forEach (http://localhost:5555/node_modules/es6-shim/es6-shim.js?1472473192889:1295:7)
   at getTransitiveModules (eval code:13672:9)
   at CompileMetadataResolver.prototype._getTransitiveNgModuleMetadata (eval code:13387:13)
   at CompileMetadataResolver.prototype.getNgModuleMetadata (eval code:13259:17)
   at RuntimeCompiler.prototype._compileComponents (eval code:15845:13)
   at RuntimeCompiler.prototype._compileModuleAndComponents (eval code:15769:13)
   at RuntimeCompiler.prototype.compileModuleAsync (eval code:15746:13)
   at PlatformRef_.prototype._bootstrapModuleWithZone (eval code:9991:13)"

【问题讨论】:

    标签: internet-explorer angular internet-explorer-10 angular-seed


    【解决方案1】:

    解决方案是从依赖项中删除 es6-shim。现在工作正常。

    【讨论】:

    • W/o polyfills 表示没有 Object.assign 方法。
    • 这个问题解决了吗?我也面临同样的问题,删除 es6-shim 后没有解决。
    • 是的,据我所知,移除 es6-shim 根本不起作用。 IE 仍然不支持 Object.assign。
    【解决方案2】:

    我认为您应该在从 @angular/core 导入 PlatformRef 并将其添加到您的 AppModule 文件的 NgModule 的 imports 配置后检查相同的内容。

    【讨论】:

    • 我试过了,但我现在得到一个错误:“TypeError: Cannot read property 'type' of null”
    • 我也尝试将它添加到模块上的提供者列表中,但它并没有解决问题。
    • 您在哪里得到“TypeError: Cannot read property 'type' of null”错误?在 '@angular/core' 中提供也已弃用,因此您必须将 Appmodule 中的 ExceptionHandler 提供程序设置更改为{ provide:ExceptionHandler,useClass: AppExceptionHandler }
    • 谢谢!我更新了提供调用并编辑了我的问题以向您提供堆栈跟踪。
    • 将declarations: [AppComponent, ...]改成declarations: [AppComponent]后请检查。
    猜你喜欢
    • 2018-04-26
    • 2017-03-01
    • 2016-12-18
    • 2016-12-20
    • 2016-12-16
    • 1970-01-01
    • 2020-09-05
    • 2018-02-10
    • 2017-01-20
    相关资源
    最近更新 更多