加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – Uncaught(承诺):没有Idle的提供者

发布时间:2020-12-17 17:42:16 所属栏目:安全 来源:网络整理
导读:我在AngularJS 2应用程序中使用ng2-idle.我能够在项目的node_modules文件夹中获取ng2-idle软件包.我正在尝试将其导入我的一个组件,如下所示: Dashboard.component.ts: import { Ng2IdleModule } from 'ng2-idle/index';import { DEFAULT_INTERRUPTSOURCES
我在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.module.ts中导入模块.这就是我收到此错误的原因吗?你能让我知道如何解决这个问题.

解决方法

根据ng2 idle示例应用程序,您需要使用.forRoot()导入模块.

https://github.com/HackedByChinese/ng2-idle-example#set-up-your-application-module

@NgModule({
  declarations: [
    AppComponent
  ],imports: [
    BrowserModule,FormsModule,HttpModule,MomentModule,NgIdleKeepaliveModule.forRoot()
  ],providers: [],bootstrap: [AppComponent]
})
export class AppModule { }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读