我是新来省道编程所以请与我裸:)使用js.dart暴露auth0 API
我写的DART Angular2应用程序,但它是不相关的问题在眼前。
我试图通过使用1https://pub.dartlang.org/packages/js公开API使用Auth0Lock。
我正在使用Dartium来调试应用程序。
所以我用以下auth0lock.dart文件揭露Auth0Lock API:
import 'package:js/js.dart';
@JS()
class Auth0Lock {
external factory Auth0Lock(String token, String domain, Object options);
external on(String event, Function func);
external show();
}
我只露出基本的东西,我需要。
然后我创建一个名为auth0_service.dart
文件具有以下代码的Angular2服务:
进口“包:angular2/core.dart”; import'auth0lock.dart'; import'app.config.dart';
@Injectable()
class Auth {
Auth0Lock lock;
Auth() {
this.lock = new Auth0Lock(configObj.auth0.apiKey, configObj.auth0.domain,{});
}
updateProfileName(data) {
var profile = data['profile'] != null ? data['profile'] : data;
print(profile['name']);
}
authenticated() {
return false;
}
login() {
this.lock.show().then(this.updateProfileName);
}
}
我还会介绍我index.html
,我加载auth0:
<!DOCTYPE html>
<html>
<head>
<title>Demo App</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="www/styles.css">
<script src="https://cdn.auth0.com/js/lock/10.0.0/lock.min.js"></script>
<script defer src="/web/main.dart" type="application/dart"></script>
<script defer src="/packages/browser/dart.js"></script>
</head>
<body>
<my-app></my-app>
</body>
</html>
当我运行我的应用程序得到ollowing错误:
EXCEPTION: No static method 'Auth0Lock.' declared in class 'Auth0Lock'.
所以Auth0Lock不是一个静态的方法,它是该类的构造函数。所以我必须以某种方式错误地使用JS api。
有什么想法?