Angular 2发布“模块导入的意外值'ElementRef'". [英] Angular 2 Release "Unexpected value 'ElementRef' imported by the module"

查看:42
本文介绍了Angular 2发布“模块导入的意外值'ElementRef'".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级到了Angular 2发行版,并且尝试使用ElementRef.起初,我收到错误 Angular2 RC5错误:zone.js:未处理的承诺拒绝:未提供ElementRef的提供程序,如下所示:

I upgraded to the release of Angular 2 and I am trying to use ElementRef. At first, I got the error Angular2 RC5 error:zone.js: Unhandled Promise rejection: No provider for ElementRef as specified here: Angular2 RC5 error:zone.js: Unhandled Promise rejection: No provider for ElementRef so I changed my code to:

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]
})

现在我得到错误(SystemJS)模块'DashboardModule'导入的意外值'ElementRef'

有什么想法吗?

提前谢谢!

编辑

是否在下面的答案中提出了建议的解决方法,现在出现此错误-这是完整的错误-有没有办法告诉我我需要在哪里从此错误中提供提供程序?

Did the suggested fix in the answer below and now have this error - here is the full error - is there a way to tell where i need to supply the provider from this error?

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

推荐答案

尝试从 imports 数组中删除 ElementRef 并将其粘贴到 providers数组:

Try to remove ElementRef from imports array and paste it into array of providers:

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]
})

这篇关于Angular 2发布“模块导入的意外值'ElementRef'".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆