Skip to content

fix(Http): export NS_HTTP_PROVIDERS to be used anywhere #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions nativescript-angular/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {RootRenderer, Renderer} from '@angular/core/src/render/api';
import {NativeScriptRootRenderer, NativeScriptRenderer} from './renderer';
import {NativeScriptDomAdapter, NativeScriptElementSchemaRegistry, NativeScriptSanitizationService} from './dom-adapter';
import {ElementSchemaRegistry, XHR, COMPILER_PROVIDERS, CompilerConfig} from '@angular/compiler';
import {Http, XHRBackend, BrowserXhr, RequestOptions, ResponseOptions, XSRFStrategy} from '@angular/http';
import {FileSystemXHR} from './http/xhr';
import {NSXSRFStrategy, NSHttp} from './http/ns-http';
import {NSFileSystem} from './file-system/ns-file-system';
import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';
import {ExceptionHandler} from '@angular/core/src/facade/exception_handler';
Expand Down Expand Up @@ -113,18 +111,6 @@ export function bootstrap(appComponentType: any,
appProviders.push(customProviders);
}

// Http Setup
// Since HTTP_PROVIDERS can be added with customProviders above, this must come after
appProviders.push([
provide(XSRFStrategy, { useValue: new NSXSRFStrategy() }),
NSFileSystem,
provide(Http, {
useFactory: (backend, options, nsFileSystem) => {
return new NSHttp(backend, options, nsFileSystem);
}, deps: [XHRBackend, RequestOptions, NSFileSystem]
})
]);

var platform = getPlatform();
if (!isPresent(platform)) {
platform = createPlatform(ReflectiveInjector.resolveAndCreate(platformProviders));
Expand Down
1 change: 1 addition & 0 deletions nativescript-angular/http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './http/ns-http';
12 changes: 11 additions & 1 deletion nativescript-angular/http/ns-http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Injectable} from '@angular/core';
import {Http, XHRConnection, ConnectionBackend, RequestOptions, RequestOptionsArgs, ResponseOptions, ResponseType, Response, Request, BrowserXhr} from '@angular/http';
import {HTTP_PROVIDERS, Http, XHRBackend, XHRConnection, ConnectionBackend, RequestOptions, RequestOptionsArgs, ResponseOptions, ResponseType, Response, Request, BrowserXhr, XSRFStrategy} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';
import {NSFileSystem} from '../file-system/ns-file-system';
Expand Down Expand Up @@ -54,3 +54,13 @@ function responseOptions(body: string | Object, status: number, url: string): Re
}));
}

export const NS_HTTP_PROVIDERS: any[] = [
HTTP_PROVIDERS,
{ provide: XSRFStrategy, useValue: new NSXSRFStrategy() },
NSFileSystem,
{ provide: Http, useFactory: (backend, options, nsFileSystem) => {
return new NSHttp(backend, options, nsFileSystem);
}, deps: [XHRBackend, RequestOptions, NSFileSystem]
}
];

4 changes: 2 additions & 2 deletions ng-sample/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ import { PageRouterOutletAppComponent, PageRouterOutletRouterProviders } from ".
import { PageRouterOutletNestedAppComponent, PageRouterOutletNestedRouterProviders } from "./examples/router/page-router-outlet-nested-test"


nativeScriptBootstrap(RendererTest);
// nativeScriptBootstrap(RendererTest);
//nativeScriptBootstrap(TabViewTest);
//nativeScriptBootstrap(Benchmark);
// nativeScriptBootstrap(ListTest);
// nativeScriptBootstrap(ListTestAsync);
//nativeScriptBootstrap(ImageTest);
// nativeScriptBootstrap(HttpTest, [HTTP_PROVIDERS]);
nativeScriptBootstrap(HttpTest);
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED], { startPageActionBarHidden: false });
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED]);
//nativeScriptBootstrap(ModalTest);
Expand Down
4 changes: 3 additions & 1 deletion ng-sample/app/examples/http/http-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component} from '@angular/core';
import {Http} from '@angular/http';
import {NS_HTTP_PROVIDERS} from 'nativescript-angular/http';
import 'rxjs/add/operator/map';

/* IMPORTANT
Expand All @@ -22,7 +23,8 @@ https://blog.nraboy.com/2015/12/fix-ios-9-app-transport-security-issues-in-nativ
`Button {
margin-bottom:20;
}`
]
],
providers: [NS_HTTP_PROVIDERS]
})
export class HttpTest {
public title: string;
Expand Down
129 changes: 65 additions & 64 deletions ng-sample/package.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,66 @@
{
"name": "tns-template-hello-world",
"main": "app.js",
"version": "1.1.0",
"author": "Telerik <[email protected]>",
"description": "Nativescript hello-world project template",
"license": "BSD",
"keywords": [
"telerik",
"mobile",
"nativescript",
"{N}",
"tns",
"appbuilder",
"template"
],
"repository": {
"type": "git",
"url": "git://github.com/NativeScript/template-hello-world.git"
},
"bugs": {
"url": "https://github.com/NativeScript/template-hello-world/issues"
},
"homepage": "https://github.com/NativeScript/template-hello-world",
"dependencies": {
"tns-core-modules": ">=2.1.0 || >=2.1.0-2016",
"nativescript-angular": "^0.2.0",
"nativescript-intl": "^0.0.2",
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/platform-server": "2.0.0-rc.3",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.7",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"reflect-metadata": "^0.1.3",
"parse5": "1.4.2",
"punycode": "1.3.2",
"querystring": "0.2.0",
"url": "0.10.3"
},
"devDependencies": {
"babel-traverse": "6.9.0",
"babel-types": "6.10.0",
"babylon": "6.8.1",
"filewalker": "0.1.2",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.1",
"nativescript-dev-webpack": "0.0.13",
"typescript": "^1.8.10"
},
"nativescript": {
"id": "org.nativescript.ngsample",
"tns-android": {
"version": "2.1.1"
},
"tns-ios": {
"version": "2.1.0"
}
}
}
"name": "tns-template-hello-world",
"main": "app.js",
"version": "1.1.0",
"author": "Telerik <[email protected]>",
"description": "Nativescript hello-world project template",
"license": "BSD",
"keywords": [
"telerik",
"mobile",
"nativescript",
"{N}",
"tns",
"appbuilder",
"template"
],
"repository": {
"type": "git",
"url": "git://github.com/NativeScript/template-hello-world.git"
},
"bugs": {
"url": "https://github.com/NativeScript/template-hello-world/issues"
},
"homepage": "https://github.com/NativeScript/template-hello-world",
"dependencies": {
"tns-core-modules": ">=2.1.0 || >=2.1.0-2016",
"nativescript-angular": "^0.2.0",
"nativescript-intl": "^0.0.2",
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/platform-server": "2.0.0-rc.3",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.7",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"reflect-metadata": "^0.1.3",
"parse5": "1.4.2",
"punycode": "1.3.2",
"querystring": "0.2.0",
"url": "0.10.3"
},
"devDependencies": {
"babel-traverse": "6.9.0",
"babel-types": "6.10.0",
"babylon": "6.8.1",
"filewalker": "0.1.2",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.1",
"nativescript-dev-webpack": "0.0.13",
"shelljs": "^0.7.0",
"typescript": "^1.8.10"
},
"nativescript": {
"id": "org.nativescript.ngsample",
"tns-android": {
"version": "2.1.1"
},
"tns-ios": {
"version": "2.1.0"
}
}
}