gpt4 book ai didi

intellij-idea - 使用 dart 为 angular2 组件定义提供程序

转载 作者:行者123 更新时间:2023-12-03 03:18:17 25 4
gpt4 key购买 nike

我正在使用 Intellij 编写一个 angular2 dart 应用程序。

我创建了一个名为 Auth 的提供程序应该注入(inject)到应用程序组件中。

我使用以下代码定义了 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);
}
}

以及使用以下代码的应用程序组件:
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 正在使用错误消息 arguments of constant creation must be constant expressions 提示提供程序数组.

我是 dart 的新手......但是如果组件配置需要 consts,我如何提供要在那里使用的类?

谢谢

最佳答案

只需添加 const应该做:

providers: const [Auth]

您看到的错误是因为 [Auth]创建一个 List,虽然它只包含一个 const 成员,但它本身不是常量。 (例如,可以添加或清除它。) Dart 要求您明确指定 List 是常量。

关于intellij-idea - 使用 dart 为 angular2 组件定义提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38705867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com