2
我正在使用AngularJS 2应用程序中的ng2-idle。我能够在项目的node_modules文件夹中获得ng2-idle软件包。我试图将其导入到类似下面的我的组件之一:未捕获(承诺):没有空闲提供者
Dashboard.component.ts:
import { Ng2IdleModule } from 'ng2-idle/index';
import { DEFAULT_INTERRUPTSOURCES } from 'ng2-idle/index';
import { Idle } from 'ng2-idle/idle';
//location and router
import { Router } from '@angular/router';
import { AppComponent } from '../../app.component';
@Component({
selector: 'dashboard',
templateUrl: './dashboard.component.html'
})
export class DashboardComponent {
private showBusyIndicator: boolean = false;
private idleState: string = 'Not started.';
private timedOut: boolean = false;
constructor(@Host() @Inject(forwardRef(() => AppComponent)) private app: AppComponent,
private idle: Idle) {//throws an error when I include it in the constructor
}
}
当我这样做,我得到以下错误:
message:Uncaught (in promise): Error: Error in ./DashboardComponent class DashboardComponent_Host - inline template:0:0 caused by: No provider for Idle!
Error: No provider for Idle!
at NoProviderError.BaseError [as constructor] (http://localhost:4200/main.bundle.js:7103:34)
at NoProviderError.AbstractProviderError [as constructor] (http://localhost:4200/main.bundle.js:62865:16)
at new NoProviderError (http://localhost:4200/main.bundle.js:62896:16)
at ReflectiveInjector_._throwOrNull (http://localhost:4200/main.bundle.js:101281:19)
at ReflectiveInjector_._getByKeyDefault (http://localhost:4200/main.bundle.js:101309:25)
at ReflectiveInjector_._getByKey (http://localhost:4200/main.bundle.js:101272:25)
at ReflectiveInjector_.get (http://localhost:4200/main.bundle.js:101081:21)
at AppModuleInjector.NgModuleInjector.get (http://localhost:4200/main.bundle.js:63774:52)
at ElementInjector.get (http://localhost:4200/main.bundle.js:101472:48)
at ElementInjector.get (http://localhost:4200/main.bundle.js:101472:48)
source:
stack trace:null
当我将它导入到AppModule中我收到以下错误:
metadata_resolver.js:227Uncaught Error: Unexpected value 'Ng2IdleModule' imported by the module 'AppModule'(…)
我没有在我的app.mo中导入模块dule.ts.这是为什么我得到这个错误?你能让我知道我该如何解决这个问题。
好了,你为什么不尝试的AppModule进口呢? –
@AlexanderCiesielski我更新了这个问题,当我尝试将它导入到AppModule中时出现错误。 – Valla