我是新來省道編程所以請與我裸:)使用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。
有什麼想法?