Я работаю с ng2-idle в приложении AngularJS 2. Я смог получить пакет ng2-idle в папке node_modules проекта. Я пытаюсь импортировать его в один из моих компонентов, как следующие:Uncaught (in prom): Нет провайдера для 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