我升级到Angular 2的版本,我正在尝试使用ElementRef。首先,我收到了此处指定的错误projectile-invalidate-cache
: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) Unexpected value 'ElementRef' imported by the module 'DashboardModule'
答案 0 :(得分:1)
尝试从ElementRef
数组中移除imports
并将其粘贴到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]
})
答案 1 :(得分:0)
在您需要的个别组件级别处使用它。
import { ElementRef } from '@angular/core';
@Component({
....
})
export class DashboardComponent{
constructor(private el:ElementRef){}
}