Skip to content

Exception: Server error; cause: Type 'NativeJavaScriptObject' is not a subtype of expected type 'HttpRequest'. #33154

Open
@RSd108

Description

Dart VM version: 2.0.0-dev.55.0 (Mon May 14 09:23:07 2018 +0200) on "windows_x64"
Chrome Version 66.0.3359.139 (Official Build) (64-bit)

I'm playing with heros tutorial from https://github.com/angular-examples/toh-6/tree/master

hero_service.dart

@Injectable()
class HeroService {
  static final _headers = {'Content-Type': 'application/json'};
  static const _heroesUrl = 'api/heroes'; // URL to web API

  final Client _http;

  HeroService(this._http);

  Future<List<Hero>> getAll() async {
    try {
      final response = await _http.get(_heroesUrl);
      final heroes = (_extractData(response) as List)
          .map((json) => new Hero.fromJson(json))
          .toList();
      return heroes;
    } catch (e) {
      throw _handleError(e);
    }
  }...

I inject browserclient in main.dart

@GenerateInjector([
  routerProvidersHash, // You can use routerProviders in production
  //const ClassProvider(Client, useClass: InMemoryDataService),
  // Using a real back end?
  // Import 'package:http/browser_client.dart' and change the above to:
     const ClassProvider(Client, useClass: BrowserClient),
])
final InjectorFactory injector = self.injector$Injector;

void main() {
  runApp(ng.AppComponentNgFactory, createInjector: injector);
}

When calling _http.get(_heroesUrl) on the injected BrowserClient instance, I get the below exception being thrown. sdk version 2.0.0-dev.55.0

EXCEPTION: Exception: Server error; cause: Type 'NativeJavaScriptObject' is not a subtype of expected type 'HttpRequest'.
STACKTRACE:
packages/$sdk/dev_compiler/amd/dart_sdk.js 4823:29 throw
packages/angular_tour_of_heroes/src/hero_service.ddc.js 32:21 getAll
packages/$sdk/dev_compiler/amd/dart_sdk.js 23502:38 onError
packages/stack_trace/stack_trace.ddc.js 142:98 .dart.fn
packages/stack_trace/stack_trace.ddc.js 188:16 [_run]
packages/stack_trace/stack_trace.ddc.js 142:80 arg
packages/angular/src/core/zone/ng_zone.ddc.js 115:18 arg

Metadata

Assignees

No one assigned

    Labels

    area-webUse area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.library-htmlweb-librariesIssues impacting dart:html, etc., libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions