gpt4 book ai didi

javascript - Angular 2 Release "Unexpected value ' ElementRef' 由模块导入”

转载 作者:太空宇宙 更新时间:2023-11-04 16:31:03 25 4
gpt4 key购买 nike

我升级到了 Angular 2 版本,并且正在尝试使用 ElementRef。首先,我收到错误 Angular2 RC5 error:zone.js: Unhandled Promise Rejection: No provider for ElementRef ,如下所示:Angular2 RC5 error:zone.js: Unhandled Promise rejection: No provider for 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]
})

现在我收到错误(SystemJS)模块“DashboardModule”导入的意外值“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

最佳答案

尝试从 imports 数组中删除 ElementRef 并将其粘贴到 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]
})

关于javascript - Angular 2 Release "Unexpected value ' ElementRef' 由模块导入”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39808264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com