Angular4:没有t的提供者!导入ng2-cache-service模块后

时间:2017-07-24 09:43:36

标签: angular caching service node-modules provider

我有一个带有此节点模块的角度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

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

通过将模块切换到原始文件ng2-cache by Jackson88来解决,错误只发生在分叉模块中。