Skip to content

Commit e6b8b72

Browse files
author
Alexander Vakrilov
authored
Merge pull request #321 from NathanWalker/http-adjustment
fix(Http): export NS_HTTP_PROVIDERS to be used anywhere
2 parents b9de97a + a95735b commit e6b8b72

File tree

6 files changed

+82
-82
lines changed

6 files changed

+82
-82
lines changed

Diff for: nativescript-angular/application.ts

-14
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import {RootRenderer, Renderer} from '@angular/core/src/render/api';
1616
import {NativeScriptRootRenderer, NativeScriptRenderer} from './renderer';
1717
import {NativeScriptDomAdapter, NativeScriptElementSchemaRegistry, NativeScriptSanitizationService} from './dom-adapter';
1818
import {ElementSchemaRegistry, XHR, COMPILER_PROVIDERS, CompilerConfig} from '@angular/compiler';
19-
import {Http, XHRBackend, BrowserXhr, RequestOptions, ResponseOptions, XSRFStrategy} from '@angular/http';
2019
import {FileSystemXHR} from './http/xhr';
21-
import {NSXSRFStrategy, NSHttp} from './http/ns-http';
2220
import {NSFileSystem} from './file-system/ns-file-system';
2321
import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';
2422
import {ExceptionHandler} from '@angular/core/src/facade/exception_handler';
@@ -113,18 +111,6 @@ export function bootstrap(appComponentType: any,
113111
appProviders.push(customProviders);
114112
}
115113

116-
// Http Setup
117-
// Since HTTP_PROVIDERS can be added with customProviders above, this must come after
118-
appProviders.push([
119-
provide(XSRFStrategy, { useValue: new NSXSRFStrategy() }),
120-
NSFileSystem,
121-
provide(Http, {
122-
useFactory: (backend, options, nsFileSystem) => {
123-
return new NSHttp(backend, options, nsFileSystem);
124-
}, deps: [XHRBackend, RequestOptions, NSFileSystem]
125-
})
126-
]);
127-
128114
var platform = getPlatform();
129115
if (!isPresent(platform)) {
130116
platform = createPlatform(ReflectiveInjector.resolveAndCreate(platformProviders));

Diff for: nativescript-angular/http.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './http/ns-http';

Diff for: nativescript-angular/http/ns-http.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Injectable} from '@angular/core';
2-
import {Http, XHRConnection, ConnectionBackend, RequestOptions, RequestOptionsArgs, ResponseOptions, ResponseType, Response, Request, BrowserXhr} from '@angular/http';
2+
import {HTTP_PROVIDERS, Http, XHRBackend, XHRConnection, ConnectionBackend, RequestOptions, RequestOptionsArgs, ResponseOptions, ResponseType, Response, Request, BrowserXhr, XSRFStrategy} from '@angular/http';
33
import {Observable} from 'rxjs/Observable';
44
import 'rxjs/add/observable/fromPromise';
55
import {NSFileSystem} from '../file-system/ns-file-system';
@@ -54,3 +54,13 @@ function responseOptions(body: string | Object, status: number, url: string): Re
5454
}));
5555
}
5656

57+
export const NS_HTTP_PROVIDERS: any[] = [
58+
HTTP_PROVIDERS,
59+
{ provide: XSRFStrategy, useValue: new NSXSRFStrategy() },
60+
NSFileSystem,
61+
{ provide: Http, useFactory: (backend, options, nsFileSystem) => {
62+
return new NSHttp(backend, options, nsFileSystem);
63+
}, deps: [XHRBackend, RequestOptions, NSFileSystem]
64+
}
65+
];
66+

Diff for: ng-sample/app/app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ import { PageRouterOutletAppComponent, PageRouterOutletRouterProviders } from ".
4242
import { PageRouterOutletNestedAppComponent, PageRouterOutletNestedRouterProviders } from "./examples/router/page-router-outlet-nested-test"
4343

4444

45-
nativeScriptBootstrap(RendererTest);
45+
// nativeScriptBootstrap(RendererTest);
4646
//nativeScriptBootstrap(TabViewTest);
4747
//nativeScriptBootstrap(Benchmark);
4848
// nativeScriptBootstrap(ListTest);
4949
// nativeScriptBootstrap(ListTestAsync);
5050
//nativeScriptBootstrap(ImageTest);
51-
// nativeScriptBootstrap(HttpTest, [HTTP_PROVIDERS]);
51+
nativeScriptBootstrap(HttpTest);
5252
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED], { startPageActionBarHidden: false });
5353
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED]);
5454
//nativeScriptBootstrap(ModalTest);

Diff for: ng-sample/app/examples/http/http-test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component} from '@angular/core';
22
import {Http} from '@angular/http';
3+
import {NS_HTTP_PROVIDERS} from 'nativescript-angular/http';
34
import 'rxjs/add/operator/map';
45

56
/* IMPORTANT
@@ -22,7 +23,8 @@ https://blog.nraboy.com/2015/12/fix-ios-9-app-transport-security-issues-in-nativ
2223
`Button {
2324
margin-bottom:20;
2425
}`
25-
]
26+
],
27+
providers: [NS_HTTP_PROVIDERS]
2628
})
2729
export class HttpTest {
2830
public title: string;

Diff for: ng-sample/package.json

+65-64
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,66 @@
11
{
2-
"name": "tns-template-hello-world",
3-
"main": "app.js",
4-
"version": "1.1.0",
5-
"author": "Telerik <[email protected]>",
6-
"description": "Nativescript hello-world project template",
7-
"license": "BSD",
8-
"keywords": [
9-
"telerik",
10-
"mobile",
11-
"nativescript",
12-
"{N}",
13-
"tns",
14-
"appbuilder",
15-
"template"
16-
],
17-
"repository": {
18-
"type": "git",
19-
"url": "git://github.com/NativeScript/template-hello-world.git"
20-
},
21-
"bugs": {
22-
"url": "https://github.com/NativeScript/template-hello-world/issues"
23-
},
24-
"homepage": "https://github.com/NativeScript/template-hello-world",
25-
"dependencies": {
26-
"tns-core-modules": ">=2.1.0 || >=2.1.0-2016",
27-
"nativescript-angular": "^0.2.0",
28-
"nativescript-intl": "^0.0.2",
29-
"@angular/common": "2.0.0-rc.3",
30-
"@angular/compiler": "2.0.0-rc.3",
31-
"@angular/core": "2.0.0-rc.3",
32-
"@angular/http": "2.0.0-rc.3",
33-
"@angular/platform-browser": "2.0.0-rc.3",
34-
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
35-
"@angular/platform-server": "2.0.0-rc.3",
36-
"@angular/router-deprecated": "2.0.0-rc.2",
37-
"@angular/router": "3.0.0-alpha.7",
38-
"rxjs": "5.0.0-beta.6",
39-
"zone.js": "^0.6.12",
40-
"reflect-metadata": "^0.1.3",
41-
"parse5": "1.4.2",
42-
"punycode": "1.3.2",
43-
"querystring": "0.2.0",
44-
"url": "0.10.3"
45-
},
46-
"devDependencies": {
47-
"babel-traverse": "6.9.0",
48-
"babel-types": "6.10.0",
49-
"babylon": "6.8.1",
50-
"filewalker": "0.1.2",
51-
"lazy": "1.0.11",
52-
"nativescript-dev-typescript": "^0.3.1",
53-
"nativescript-dev-webpack": "0.0.13",
54-
"typescript": "^1.8.10"
55-
},
56-
"nativescript": {
57-
"id": "org.nativescript.ngsample",
58-
"tns-android": {
59-
"version": "2.1.1"
60-
},
61-
"tns-ios": {
62-
"version": "2.1.0"
63-
}
64-
}
65-
}
2+
"name": "tns-template-hello-world",
3+
"main": "app.js",
4+
"version": "1.1.0",
5+
"author": "Telerik <[email protected]>",
6+
"description": "Nativescript hello-world project template",
7+
"license": "BSD",
8+
"keywords": [
9+
"telerik",
10+
"mobile",
11+
"nativescript",
12+
"{N}",
13+
"tns",
14+
"appbuilder",
15+
"template"
16+
],
17+
"repository": {
18+
"type": "git",
19+
"url": "git://github.com/NativeScript/template-hello-world.git"
20+
},
21+
"bugs": {
22+
"url": "https://github.com/NativeScript/template-hello-world/issues"
23+
},
24+
"homepage": "https://github.com/NativeScript/template-hello-world",
25+
"dependencies": {
26+
"tns-core-modules": ">=2.1.0 || >=2.1.0-2016",
27+
"nativescript-angular": "^0.2.0",
28+
"nativescript-intl": "^0.0.2",
29+
"@angular/common": "2.0.0-rc.3",
30+
"@angular/compiler": "2.0.0-rc.3",
31+
"@angular/core": "2.0.0-rc.3",
32+
"@angular/http": "2.0.0-rc.3",
33+
"@angular/platform-browser": "2.0.0-rc.3",
34+
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
35+
"@angular/platform-server": "2.0.0-rc.3",
36+
"@angular/router-deprecated": "2.0.0-rc.2",
37+
"@angular/router": "3.0.0-alpha.7",
38+
"rxjs": "5.0.0-beta.6",
39+
"zone.js": "^0.6.12",
40+
"reflect-metadata": "^0.1.3",
41+
"parse5": "1.4.2",
42+
"punycode": "1.3.2",
43+
"querystring": "0.2.0",
44+
"url": "0.10.3"
45+
},
46+
"devDependencies": {
47+
"babel-traverse": "6.9.0",
48+
"babel-types": "6.10.0",
49+
"babylon": "6.8.1",
50+
"filewalker": "0.1.2",
51+
"lazy": "1.0.11",
52+
"nativescript-dev-typescript": "^0.3.1",
53+
"nativescript-dev-webpack": "0.0.13",
54+
"shelljs": "^0.7.0",
55+
"typescript": "^1.8.10"
56+
},
57+
"nativescript": {
58+
"id": "org.nativescript.ngsample",
59+
"tns-android": {
60+
"version": "2.1.1"
61+
},
62+
"tns-ios": {
63+
"version": "2.1.0"
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)