我确定这是一个基本错误,但是在Dart中使用BrowserClient时似乎无法构建Angular2应用程序。

主镖

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提出请求。

最佳答案

不可注入(inject)AFAICT中的BrowserClient

试试这个:

BrowserClient newBrowserClient() => new BrowserClient();
...
const Provider(BrowserClient, useFactory: newBrowserClient)

显然,您需要在发布依赖项中包含http包。

关于angular - Dart找不到BrowserClient,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40053671/

10-10 17:56