Javascript 角度2释放“;意外值';ElementRef';“由模块导入”;

Javascript 角度2释放“;意外值';ElementRef';“由模块导入”;,javascript,angular,Javascript,Angular,我升级到Angular 2的发行版,并尝试使用ElementRef。首先,我得到了错误Angular2 RC5 error:zone.js:未处理的承诺拒绝:ElementRef没有提供程序,如下所述:因此我将代码更改为: import { NgModule, CUSTOM_ELEMENTS_SCHEMA, ElementRef } from '@angular/core'; @NgModule({ declarations: [DashboardComponent, Wid

我升级到Angular 2的发行版,并尝试使用ElementRef。首先,我得到了错误
Angular2 RC5 error:zone.js:未处理的承诺拒绝:ElementRef没有提供程序
,如下所述:因此我将代码更改为:

import { NgModule, CUSTOM_ELEMENTS_SCHEMA, ElementRef }       from '@angular/core';
@NgModule({
    declarations: [DashboardComponent, WidgetBankComponent, DataTableDirectives, OrderBy],
    exports: [DashboardComponent, WidgetBankComponent],
    imports: [BrowserModule, HttpModule, FormsModule, ChartsModule, ElementRef],
    providers: [ChartService, GridService, WidgetsControlService, GridViewService, ApplicationSettingsService, DataService, ToolsService, LocalStorageService, RuntimeCompiler, COMPILER_PROVIDERS, NgGrid, NgGridItem],
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
现在我得到了模块“DashboardModule”导入的错误
(SystemJS)意外值“ElementRef”

有什么想法吗

提前谢谢你

编辑

下面的答案中建议的修复是否存在此错误?这是完整的错误。是否有方法告诉我需要从何处提供此错误的提供程序

zone.js:355 Unhandled Promise rejection: No provider for ElementRef! ; Zone: <root> ; Task: Promise.then ; Value: NoProviderError {_nativeError: Error: No provider for ElementRef!
    at NoProviderError.Error (native)
    at NoProviderError.Base…, keys: Array[1], injectors: Array[1]}_nativeError: Error: No provider for ElementRef!
    at NoProviderError.Error (native)
    at NoProviderError.BaseError [as constructor] (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:1248:38)
    at NoProviderError.AbstractProviderError [as constructor] (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:1703:20)
    at new NoProviderError (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:1734:20)
    at ReflectiveInjector_._throwOrNull (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3331:23)
    at ReflectiveInjector_._getByKeyDefault (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3359:29)
    at ReflectiveInjector_._getByKey (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3322:29)
    at ReflectiveInjector_.get (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3131:25)
    at NgModuleInjector.AppModuleInjector.createInternal (AppModule.ngfactory.js:310:75)
    at NgModuleInjector.create (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:7192:80)constructResolvingMessage: (keys)injectors: Array[1]keys: Array[1]message: (...)name: (...)stack: (...)__proto__: AbstractProviderError Error: No provider for ElementRef!
    at NoProviderError.Error (native)
    at NoProviderError.BaseError [as constructor] (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:1248:38)
    at NoProviderError.AbstractProviderError [as constructor] (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:1703:20)
    at new NoProviderError (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:1734:20)
    at ReflectiveInjector_._throwOrNull (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3331:23)
    at ReflectiveInjector_._getByKeyDefault (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3359:29)
    at ReflectiveInjector_._getByKey (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3322:29)
    at ReflectiveInjector_.get (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:3131:25)
    at NgModuleInjector.AppModuleInjector.createInternal (AppModule.ngfactory.js:310:75)
    at NgModuleInjector.create (http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:7192:80)consoleError @ zone.js:355_loop_1 @ zone.js:382drainMicroTaskQueue @ zone.js:386ZoneTask.invoke @ zone.js:308
zone.js:357 Error: Uncaught (in promise): Error: No provider for ElementRef!(…)consoleError @ zone.js:357_loop_1 @ zone.js:382drainMicroTaskQueue @ zone.js:386ZoneTask.invoke @ zone.js:308
zone.js:355未处理的承诺拒绝:ElementRef!没有提供程序;区域:;任务:承诺;值:NoProviderError{u nativeError:错误:ElementRef没有提供程序!
at NoProviderError.Error(本机)
在NoProviderError.Base…,键:数组[1],注入器:数组[1]}\u nativeError:错误:ElementRef没有提供程序!
at NoProviderError.Error(本机)
at NoProviderError.BaseError[作为构造函数](http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:1248:38)
在NoProviderError.AbstractProviderError[作为构造函数](http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:1703:20)
在new NoProviderError(http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:1734:20)
在ReflectiveInjector_u.u throwOrNull处(http://localhost:56159/node_modules/@角度/核心//束/核心.umd.js:3331:23)
在ReflectiveInjector_u.\u getByKeyDefault(http://localhost:56159/node_modules/@角度/核心//束/核心.umd.js:3359:29)
在ReflectiveInjector_u.\u getByKey(http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:3322:29)
在ReflectiveInjector_2;,获取(http://localhost:56159/node_modules/@角度/核心//束/核心.umd.js:3131:25)
位于NgModuleInjector.AppModuleInjector.createInternal(AppModule.ngfactory.js:310:75)
在NgModuleInjector.create(http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:7192:80)constructResolvingMessage:(键)injectors:Array[1]键:Array[1]消息:(…)名称:(…)堆栈:(…)\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu!
at NoProviderError.Error(本机)
at NoProviderError.BaseError[作为构造函数](http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:1248:38)
在NoProviderError.AbstractProviderError[作为构造函数](http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:1703:20)
在new NoProviderError(http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:1734:20)
在ReflectiveInjector_u.u throwOrNull处(http://localhost:56159/node_modules/@角度/核心//束/核心.umd.js:3331:23)
在ReflectiveInjector_u.\u getByKeyDefault(http://localhost:56159/node_modules/@角度/核心//束/核心.umd.js:3359:29)
在ReflectiveInjector_u.\u getByKey(http://localhost:56159/node_modules/@角度/核心//bundles/core.umd.js:3322:29)
在ReflectiveInjector_2;,获取(http://localhost:56159/node_modules/@角度/核心//束/核心.umd.js:3131:25)
位于NgModuleInjector.AppModuleInjector.createInternal(AppModule.ngfactory.js:310:75)
在NgModuleInjector.create(http://localhost:56159/node_modules/@angular/core//bundles/core.umd.js:7192:80)consoleError@zone.js:355_loop_1@zone.js:382drainMicroTaskQueue@zone.js:386ZoneTask.invoke@zone.js:308
zone.js:357错误:未捕获(承诺中):错误:ElementRef没有提供程序!(…)consoleError@zone.js:357_loop_1@zone.js:382drainMicroTaskQueue@zone.js:386ZoneTask.invoke@zone.js:308

在您需要的单个组件级别使用它

import {  ElementRef } from '@angular/core';
@Component({
 ....
})
export class DashboardComponent{
    constructor(private el:ElementRef){}
}

尝试从
imports
数组中删除
ElementRef
,并将其粘贴到
提供程序的数组中

import { NgModule, CUSTOM_ELEMENTS_SCHEMA, ElementRef } from '@angular/core';
@NgModule({
    declarations: [DashboardComponent, WidgetBankComponent, DataTableDirectives, OrderBy],
    exports: [DashboardComponent, WidgetBankComponent],
    imports: [BrowserModule, HttpModule, FormsModule, ChartsModule],
    providers: [ChartService, GridService, WidgetsControlService, GridViewService, ApplicationSettingsService, DataService, ToolsService, LocalStorageService, RuntimeCompiler, COMPILER_PROVIDERS, NgGrid, NgGridItem, ElementRef],
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

然后我得到
zone.js:355未处理的承诺拒绝:ElementRef!没有提供程序;区域:;任务:承诺;值:无提供错误
。。。这让我相信我在某处引用了它,但我不知道如何找到它的位置。它可能是我的一个插件,所以我想尝试将它添加为所有插件的提供者从
imports
中删除
ElementRef
,然后按照我说的做。我从导入中删除了它,然后像你说的那样添加到组件中,现在我得到了
没有提供者…
您使用的是哪个版本的angular2?最终版本很奇怪!它应该会起作用。您在最终版本中使用的是哪个zone.js版本?
^0.6.25
是我的zone版本。我也在使用ng2图表和ng2网格库,我想它们可能在某个地方被称为ElementRef,所以我想我可以在任何地方都包含它,这会产生与原始帖子中相同的错误:(@blubberbo,你从根项目文件夹运行
tsc