找不到变量:Auth0Lock Ionic2 Auth0

Can't find variable: Auth0Lock Ionic2 Auth0

我试图将 Auth0 添加到我的 Ionic 2 应用程序中,但 运行 出现一个错误 "Can't find variable: Auth0Lock"。

我对此的疑惑是声明了变量,而且是"any"类型,本来应该没问题的,但是查看main.js编译文件的时候发现,不在那里。

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

// 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; inside Auth class

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