Skip to content

Commit 8754f8c

Browse files
committed
Merge branch 'release/3.0.0-alpha8'
2 parents 148ce4d + c7259f9 commit 8754f8c

File tree

9 files changed

+2473
-73
lines changed

9 files changed

+2473
-73
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
<a name="3.0.0-alpha8"></a>
2+
### 3.0.0-alpha8 (2016-10-30)
3+
4+
Upgrade to Angular 2.0.0 / NgModules
5+
16
<a name="3.0.0-alpha7"></a>
27
### 3.0.0-alpha7 (2016-07-30)
38

49
Making sure it is usable via TypeScript as well (export d.ts files).
510

11+
612
<a name="3.0.0-alpha2"></a>
713
### 3.0.0-alpha2 (2016-07-24)
814

README.md

+18-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Angular2 services to consume [WP-API v2](http://v2.wp-api.org/)
77

88
[Live Demo](https://plnkr.co/edit/hqE4bvbM6HXql5Insjx8?p=preview)
99

10-
If you want to use AngularJS v1, here is the latest version: [v2.0.0-rc3](https://github.com/shprink/wp-api-angular/tree/v2.0.0-rc3)
10+
If you want to use AngularJS v1, here is the latest version: [v2.0.0-rc3](https://www.npmjs.com/package/wp-api-angularjs). `npm i wp-api-angularjs@v2.0.0-rc3`
1111

1212
## Installation
1313

@@ -27,21 +27,23 @@ UMD files are available `wp-api-angular.umd.js` and `wp-api-angular.umd.min.js`,
2727

2828

2929
```js
30-
import {
31-
WPAPI_PROVIDERS,
32-
defaultWpApi
33-
} from 'wp-api-angular';
34-
35-
import {App} from './app';
36-
37-
bootstrap(App, [
38-
WPAPI_PROVIDERS,
39-
defaultWpApi({
40-
baseUrl: "http://YOUR_DOMAIN/wp-json/",
41-
namespace: '/wp/v2' // (optional, default: '/wp/v2')
42-
})
43-
]);
44-
30+
import { NgModule } from '@angular/core';
31+
import { BrowserModule } from '@angular/platform-browser';
32+
import { WpApiModule } from 'wp-api-angular'
33+
import { App } from './app';
34+
35+
@NgModule({
36+
imports: [
37+
BrowserModule,
38+
WpApiModule.initializeApp({
39+
baseUrl: "http://YOUR_DOMAIN/wp-json/",
40+
namespace: '/wp/v2' // (optional, default: '/wp/v2')
41+
})
42+
],
43+
declarations: [App],
44+
bootstrap: [App]
45+
})
46+
export class AppModule { }
4547
```
4648

4749
## API

demo/app.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ export class App {
8484
service[method].apply(service, parameters).toPromise()
8585
.then(response => response.json())
8686
.then(body => {
87-
console.groupCollapsed(serviceName, method, JSON.stringify(parameters));
88-
console.log(body);
89-
console.groupEnd()
87+
// console.groupCollapsed(serviceName, method, JSON.stringify(parameters));
88+
// console.log(body);
89+
// console.groupEnd()
9090
this.requests.push({ serviceName: serviceName.slice(5), method, success: true })
9191
})
9292
.catch(error => {

demo/index.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
import {provide} from '@angular/core';
2-
import { bootstrap } from '@angular/platform-browser-dynamic';
3-
import 'rxjs/add/operator/toPromise';
4-
import {
5-
WPAPI_PROVIDERS,
6-
defaultWpApi
7-
} from '../dist/wp-api-angular'
8-
let config = require('../config.json');
1+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2+
import { AppModule } from './module';
93

10-
import {App} from './app';
11-
12-
bootstrap(App, [
13-
WPAPI_PROVIDERS,
14-
defaultWpApi({
15-
baseUrl: config.baseUrl
16-
})
17-
]);
4+
platformBrowserDynamic().bootstrapModule(AppModule);

demo/module.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import 'rxjs/add/operator/toPromise';
4+
import {
5+
WpApiModule
6+
} from '../dist/wp-api-angular'
7+
import { App } from './app';
8+
9+
let config = require('../config.json');
10+
11+
console.info('config', config);
12+
13+
@NgModule({
14+
imports: [
15+
BrowserModule,
16+
WpApiModule.initializeApp({
17+
baseUrl: config.baseUrl
18+
})
19+
],
20+
declarations: [App],
21+
bootstrap: [App]
22+
})
23+
export class AppModule { }

package.json

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wp-api-angular",
3-
"version": "3.0.0-alpha7",
3+
"version": "3.0.0-alpha8",
44
"description": "WordPress WP-API v2 client for Angular2",
55
"main": "wp-api-angular.js",
66
"typings": "wp-api-angular.d.ts",
@@ -34,31 +34,28 @@
3434
"url": "https://github.com/shprink/wp-api-angular/issues"
3535
},
3636
"homepage": "https://github.com/shprink/wp-api-angular",
37+
"dependencies": {
38+
"@angular/common": "^2.0.0",
39+
"@angular/compiler": "^2.0.0",
40+
"@angular/core": "^2.0.0",
41+
"@angular/http": "^2.1.2",
42+
"@angular/platform-browser": "^2.0.0",
43+
"@angular/platform-browser-dynamic": "^2.0.0",
44+
"rxjs": "5.0.0-beta.12"
45+
},
3746
"devDependencies": {
38-
"@angular/common": "^2.0.0-rc.4",
39-
"@angular/compiler": "^2.0.0-rc.4",
40-
"@angular/core": "^2.0.0-rc.4",
41-
"@angular/http": "^2.0.0-rc.4",
42-
"@angular/platform-browser": "^2.0.0-rc.4",
43-
"@angular/platform-browser-dynamic": "^2.0.0-rc.4",
4447
"babel-core": "^6.10.4",
4548
"babel-loader": "^6.2.4",
4649
"core-js": "^2.4.0",
4750
"html-webpack-plugin": "~2.22.0",
4851
"json-loader": "^0.5.2",
4952
"path": "^0.4.9",
5053
"reflect-metadata": "^0.1.3",
51-
"rxjs": "5.0.0-beta.6",
5254
"ts-loader": "0.8.1",
5355
"typescript": "~1.8.10",
5456
"util": "^0.10.3",
5557
"webpack": "~1.13.1",
5658
"webpack-dev-server": "~1.14.1",
5759
"zone.js": "^0.6.12"
58-
},
59-
"peerDependencies": {
60-
"@angular/core": "2.0.0-rc.2 || 2.0.0-rc.3 || 2.0.0-rc.4 || 2.0.0-rc.5 || 2.0.0-rc.6 || 2.0.0-rc.7 || 2.0.0-rc.8 || 2.0.0-rc.9",
61-
"@angular/http": "2.0.0-rc.2 || 2.0.0-rc.3 || 2.0.0-rc.4 || 2.0.0-rc.5 || 2.0.0-rc.6 || 2.0.0-rc.7 || 2.0.0-rc.8 || 2.0.0-rc.9",
62-
"rxjs": "5.0.0-beta.6"
6360
}
6461
}

src/wp-api-angular.ts

+31-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {
2-
provide,
3-
Provider
2+
Provider,
3+
NgModule,
4+
ModuleWithProviders
45
} from '@angular/core';
56
import 'rxjs';
6-
import { Http, HTTP_PROVIDERS } from '@angular/http';
7+
import { Http, HttpModule } from '@angular/http';
78

89
import { stripTrailingSlash } from './utils';
910
import { WpApiApp, WpApiConfig } from './tokens';
@@ -35,28 +36,34 @@ export interface WpApiAppConfig {
3536
namespace?: string;
3637
}
3738

38-
export const defaultWpApi = (config: WpApiAppConfig): Provider => {
39-
// remove a trailing slash
40-
config.baseUrl = stripTrailingSlash(config.baseUrl);
41-
config.namespace = config.namespace || '/wp/v2';
42-
return provide(WpApiConfig, {
43-
useValue: config
44-
});
45-
};
39+
@NgModule({
40+
imports: [
41+
HttpModule
42+
]
43+
})
44+
export class WpApiModule {
45+
static initializeApp(config: WpApiAppConfig): ModuleWithProviders {
46+
config.baseUrl = stripTrailingSlash(config.baseUrl);
47+
config.namespace = config.namespace || '/wp/v2';
4648

47-
export const WPAPI_PROVIDERS: any[] = [
48-
HTTP_PROVIDERS,
49-
createProvider(WpApiPosts),
50-
createProvider(WpApiPages),
51-
createProvider(WpApiComments),
52-
createProvider(WpApiTypes),
53-
createProvider(WpApiMedia),
54-
createProvider(WpApiUsers),
55-
createProvider(WpApiTaxonomies),
56-
createProvider(WpApiStatuses),
57-
createProvider(WpApiTerms),
58-
createProvider(WpApiCustom)
59-
];
49+
return {
50+
ngModule: WpApiModule,
51+
providers: [
52+
{ provide: WpApiConfig, useValue: config },
53+
createProvider(WpApiPosts),
54+
createProvider(WpApiPages),
55+
createProvider(WpApiComments),
56+
createProvider(WpApiTypes),
57+
createProvider(WpApiMedia),
58+
createProvider(WpApiUsers),
59+
createProvider(WpApiTaxonomies),
60+
createProvider(WpApiStatuses),
61+
createProvider(WpApiTerms),
62+
createProvider(WpApiCustom)
63+
]
64+
};
65+
}
66+
}
6067

6168
function createProvider(service) {
6269
return {

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
entry: {
1111
aPolyfills: [
1212
'core-js',
13-
'reflect-metadata',
13+
'reflect-metadata/Reflect.js',
1414
'zone.js'
1515
],
1616
bVendors: [

0 commit comments

Comments
 (0)