【问题标题】:Can't find variable: Auth0Lock Ionic2 Auth0找不到变量:Auth0Lock Ionic2 Auth0
【发布时间】:2017-06-10 18:04:15
【问题描述】:

我试图将 Auth0 添加到我的 Ionic 2 应用程序中,但遇到了“找不到变量:Auth0Lock”的错误。

我对此感到困惑的是,该变量已声明,并且它是“any”类型,所以应该没问题,但是当我检查 main.js 编译文件时,我发现它不存在。

【问题讨论】:

    标签: angular login ionic2 auth0


    【解决方案1】:

    为了解决这个问题,我对从 Auth0 快速入门页面获得的 Auth 类进行了简单的更改,如下所示:

    // app/auth.service.ts
    
    import { Injectable }      from '@angular/core';
    import { tokenNotExpired } from 'angular2-jwt';
    
    // Avoid name not found warnings
    declare var Auth0Lock: any;
    
    @Injectable()
    export class Auth {
    // Configure Auth0
    lock = new Auth0Lock('client_id','domain', {});
    

    为了解决 Auth0Lock 没有被添加到编译的 js 文件中的问题(也就是说,它没有被添加到实际应用程序上运行的程序中),我做了这个更改:

    import { Injectable }      from '@angular/core';
    import { tokenNotExpired } from 'angular2-jwt';
    import Auth0Lock from 'auth0-lock';
    
    
    @Injectable()
    export class Auth {
    // Avoid name not found warnings
    Auth0Lock: any;
    
    // Configure Auth0
    lock = new Auth0Lock('client_id','domain', {});
    

    1.) 添加“从'auth0-lock'导入Auth0Lock;

    2.) 删除 declare var Auth0Lock: any;

    3.) 添加了Auth0Lock: any; Auth 类中

    就是这样! (现在不要忘记在 CORS 等中设置 IP 地址;))

    【讨论】:

      猜你喜欢
      • 2016-12-18
      • 2023-04-04
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 2016-10-02
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多