我有一个带有此节点模块的角度4项目,用于存储数据:DarthKurt/ng2-cache-service
但我收到此错误,仅在使用AOT编译后发生:
ng build --prod --aot
ERROR Error: Uncaught (in promise): Error: No provider for t!
我正在以这种方式导入缓存服务:
app.module.ts
...
import { CacheService } from 'ng2-cache-service';
@NgModule({
declarations: [
...
],
imports: [
...
],
providers: [
CacheService, {
provide: APP_BASE_HREF,
useValue: '/app/ecommerce/'
}],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import { CacheService } from 'ng2-cache-service';
import 'rxjs/Rx';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [ CacheService ]
})
export class AppComponent {
constructor(public http: Http, public cache: CacheService) {}
someFunc() {
this.cache.set('test', 'works');
}
}
如果我将 CacheService 添加到 app.module.ts 中的导入列表,我总是会收到以下错误:
ERROR in Unexpected value 'CacheService in /Users/rpereira/ecommerce/node_modules/ng2-cache-service/dist/src/services/cache.service.d.ts' imported by the module 'AppModule in /Users/rpereira/ecommerce/src/app/app.module.ts'. Please add a @NgModule annotation.
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/rpereira/ecommerce/src'
@ ./src/main.ts 4:0-74
@ multi ./src/main.ts
我错过了什么吗?