1

Intellij を使用して angular2 dart アプリケーションを作成しています。

Authアプリ コンポーネントに注入する必要があるというプロバイダーを作成しました。

次のコードを使用して Auth サービスを定義しました。

import 'package:angular2/core.dart';
import 'package:auth0_lock/auth0_lock.dart';
import './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']);
}

login() {
    this.lock.show(popupMode: true, options: {'authParams': {'scope': 'openid profile'}}).then(this.updateProfileName);
}
}

そして、次のコードを使用する app コンポーネント:

import 'package:angular2/core.dart';
import 'package:angular2/router.dart';
import 'welcome_component.dart';
import 'auth_service.dart';

@Component(
    selector: 'my-app',
    templateUrl: '/www/my-app.html',
   providers: [Auth]
)
@RouteConfig(const [
  const Route(path: '/welcome', component: WelcomeComponent, name: 'welcome')
])
class AppComponent {
  Auth auth;
  AppComponent(Auth auth) {
    this.auth=auth;
  }
}

intellij は、providers 配列についてエラー メッセージを表示していますarguments of constant creation must be constant expressions

私はダーツを初めて使用します...しかし、コンポーネント構成にconstが必要な場合、そこで使用されるクラスをどのように提供できますか?

ありがとう

4

1 に答える 1

3

追加constするだけでできます:

providers: const [Auth]

あなたが見ているエラーは[Auth]、const メンバーのみを含んでいますが、それ自体が定数ではない List を作成するためです。(たとえば、追加またはクリアできます。) Dart では、List が定数であることを明示的に指定する必要があります。

于 2016-08-01T18:46:12.033 に答える