我确定这是一个基本错误,但在Dart中使用BrowserClient时,我似乎无法构建Angular2应用程序。
main.dart
import 'package:angular2/platform/browser.dart';
import 'package:dartblog/app_component.dart';
import 'package:http/browser_client.dart';
void main(){
bootstrap(
AppComponent,
const [BrowserClient]
);
}
我确实改变了我的pubspec.yaml;重要的部分:
- angular2:
platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
platform_pipes:
- 'package:angular2/common.dart#COMMON_PIPES'
entry_points: web/main.dart
resolved_identifiers:
BrowserClient: 'package:http/browser_client.dart'
运行pub build
时出现的错误如下:
[Error from Dart2JS on dartblog|web/main.dart]:
web/main.template.dart:15:1:
Can't read 'package:http/browser_client.dart' (Could not find asset http|lib/browser_client.dart.).
import 'package:http/browser_client.dart';
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Warning from Dart2JS]:
web/main.dart:6:40:
Cannot resolve 'BrowserClient'.
bootstrapStatic(AppComponent, const [BrowserClient], () { ngStaticInit.initReflector(); });
^^^^^^^^^^^^^
[Error from Dart2JS]:
web/main.dart:6:40:
Not a compile-time constant.
bootstrapStatic(AppComponent, const [BrowserClient], () { ngStaticInit.initReflector(); });
^^^^^^^^^^^^^
我正在尝试使用Dart获取请求。
答案 0 :(得分:2)
BrowserClient
不能注射AFAICT。
试试这个:
BrowserClient newBrowserClient() => new BrowserClient();
...
const Provider(BrowserClient, useFactory: newBrowserClient)
显然,您需要在pub依赖项中包含http
包。