Migrated from angular/angular#9673 (comment).
Current behavior
Setup for use of the Angular http library is straightforward in ng2/ts as can be see from this excerpt of app/main.ts (v1)
taken from the HTTP dev guide chapter:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { HTTP_PROVIDERS } from '@angular/http';
import { AppComponent } from './app.component';
bootstrap(AppComponent, [ HTTP_PROVIDERS ]);
Namely, one can simply add [ HTTP_PROVIDERS ]
as second argument to bootstrap()
.
Expected/desired behavior
One would expect that a similar setup should be just as easy to do in ng2/dart; here is web/main.dart (v1)
excerpt from here:
import 'package:angular2/platform/browser.dart';
import 'package:http/browser_client.dart';
import 'package:server_communication/app_component.dart';
void main() { bootstrap(AppComponent, const [BrowserClient]); }
Attempting to run the dart code above results in the app failing and following is being reported in the Dartium console:
Exception: Cannot find reflection information on BrowserClient
.
Others report similar problems when running apps (compiled to js) under Chrome: see this SO post.
Reproduction of the problem
The simplest example I could come up with to reproduce this exception can be created as follows:
- Launch WebStorm.
- Create a new Dart Angular 2 web project.
- Open main.dart and add the following as a second argument to bootstrap():
[Object]
(use or not of const
does not seem to be pertinent here).
- Then launch the app (in Dartium) and open the JS console. The app should fail to load and "Exception: Cannot find reflection information on Object" will be shown.
What is the expected behavior?
The simple app created above should run w/o raising exceptions and it should display "My First Angular 2 App".
The only workaround that I have found is to use the following as second argument to bootstrap():
[provide(Object, useFactory: () => new Object(), deps: [])]
.
Similar problems arise if instead of [Object]
one tries to use, say, [BrowserClient]
as second argument to bootstrap()
, though, in this latter case an appropriate resolved_identifiers
entry needs to be added to the pubspec.yaml
. Replacing [Object]
by [List]
on the other hand gives stranger results.
Please tell us about your environment:
- Angular version: 2.0.0-beta.19
- Browser: tested in Dartium 45.0.2454.104 (64-bit) by myself and in Chrome by others.
- Language: Dart
** Context **
This problem manifests itself in the context of the Angular.io Tour of Heroes, part 6 and the Dev Guide HTTP chapter.
Possibly relevant ng/ng issues:
/cc @kwalrath