I built this code just to get tests running I ported from TypeScript to Dart
import 'dart:async' show Future;
import 'dart:html' show HttpRequest;
import 'dart:convert' show JSON;
class Http {
Future<Response> get(String uri) async {
final HttpRequest req = new HttpRequest()..open('GET', uri);
await req.onLoadEnd.first;
req.send();
return new Response(req);
}
}
class Response {
final HttpRequest request;
Response(this.request);
String text() => request.responseText;
dynamic json() => JSON.decode(request.response);
}
It has only a `get()` method, but other methods are quite similar.
You can get inspiration from the TypeScript source about what features to
add.
For mocking, just extend it `class MockHttp extends Http {` and override
the methods with dummy actions.
On Friday, January 22, 2016 at 7:42:35 PM UTC+1, Douglas Miller wrote:
>
> But does that work with Angular's dependency injection? I want to be able
> to mock it in tests.
>
> ...some quick googling says probably yes, I think. I'm new to Dart as well
> as Angular2, looks like I should have explored what Dart itself provides a
> bit more.
>
> On Friday, January 22, 2016 at 4:00:53 AM UTC-8, Günter Zöchbauer wrote:
>>
>> There is no Dart implementation for Http. You can just use what
>> `dart:html` or `package:http` provide or create your own wrapper class if
>> you want specific functionality.
>>
>> On Friday, January 22, 2016 at 6:08:35 AM UTC+1, Douglas Miller wrote:
>>>
>>> The api docs say there's an angular2/http library in JavaScript and
>>> TypeScript, but as far as I can tell it doesn't exist in the Dart version.
>>> Am I missing something? Is it not implemented yet? Something else?
>>>
>>> The Dart api docs essentially say "see JavaScript docs" full stop, and I
>>> was under the impression that the use of code generation meant all three
>>> languages would have all exactly the same Angular features, so I'm a bit
>>> surprised and disappointed if this is missing. Searching through the Dart
>>> source that pub got for me, angular2/http does not exist and only one class
>>> (angular2/src/services/xhr_impl) does anything with http, and that class
>>> appears to be intended for internal use only.
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.