我该如何解决“找不到名称'OktaAuthService'的错误”?

时间:2019-03-25 19:13:18

标签: angular typescript okta

我想使用Okta将身份验证输入Angular应用程序中,我逐步遵循文档中的指示:https://developer.okta.com/code/angular/okta_angular_sign-in_widget/ 但是,当我尝试启动服务器时出现错误,请您能帮我吗?

export class AppComponent {
 title = 'okta';
  isAuthenticated: boolean;

    constructor(public oktaAuth: OktaAuthService, public router: Router) {
        // Subscribe to authentication state changes
        this.oktaAuth.$authenticationState.subscribe(
            (isAuthenticated: boolean)  => this.isAuthenticated = isAuthenticated
        );
    }

    async ngOnInit() {
        // Get the authentication state for immediate use
        this.isAuthenticated = await this.oktaAuth.isAuthenticated();
    }

!控制台错误

console error

1 个答案:

答案 0 :(得分:0)

确保将适当的导入添加到您要注入的服务中。即使将Okta模块导入了您的模块ts文件中,您仍然必须将服务导入到组件中。您还必须导入路由器才能注入它(屏幕截图中有错误)。

import { Router } from '@angular/router';
import { OktaAuthService } from '@okta/okta-angular';
  

https://angular.io/tutorial/toh-pt4#update-heroescomponent