|
1 | 1 | wp-api-angularjs
|
2 | 2 | ================
|
3 | 3 |
|
4 |
| -wp-api-angularjs is under development and will only cover GET methods of the [WP-API](https://github.com/WP-API/WP-API) master branch. |
| 4 | +AngularJS services to consume [WP-API v2](http://v2.wp-api.org/) |
5 | 5 |
|
6 |
| -## Install |
7 |
| - |
8 |
| -wp-api-angularjs depends on [Restangular](https://github.com/mgonto/restangular) that itself depends on [Underscore](https://github.com/jashkenas/underscore) or [Lodash](https://github.com/lodash/lodash) |
| 6 | +## Documentation |
9 | 7 |
|
10 |
| -include the bundled version ```dist/wp-api-angularjs.bundle.js``` (that includes Restangular) or ```dist/wp-api-angularjs.js``` (that does not include Restangular) |
11 |
| - |
12 |
| -Do not forget to include [Underscore](https://github.com/jashkenas/underscore) or [Lodash](https://github.com/lodash/lodash) in your project. |
13 |
| - |
14 |
| -``` |
15 |
| -angular.module('myApp', ['wp-api-angularjs']); |
16 |
| -``` |
17 |
| - |
18 |
| -## Services |
19 |
| - |
20 |
| -### WpApiProvider |
21 |
| - |
22 |
| -wp-api-angularjs is based on Restangular therefore you can use any of the [Restangular Provider methods](https://github.com/mgonto/restangular/tree/1.4.0#configuring-in-the-config) |
23 |
| - |
24 |
| -``` |
25 |
| -.config(function(WpApiProvider) { |
26 |
| - var RestangularProvider = WpApiProvider.getRestangularProvider(); |
27 |
| - RestangularProvider.setBaseUrl('/api/v1'); |
28 |
| -}); |
29 |
| -``` |
30 |
| - |
31 |
| -wp-api-angularjs always returns promises: |
32 |
| - |
33 |
| -``` |
34 |
| -$wpApiPosts.$get(id).then(function(post) { |
35 |
| - // OK |
36 |
| - }).catch(function() { |
37 |
| - // KO |
38 |
| - }); |
39 |
| -``` |
40 |
| - |
41 |
| -### Posts ```$wpApiPosts``` |
42 |
| - |
43 |
| -``` |
44 |
| -// Get latests posts |
45 |
| -$wpApiPosts.$getList(); |
46 |
| -
|
47 |
| -// Get filtered posts |
48 |
| -$wpApiPosts.$getList({ |
49 |
| - "page" : 2, |
50 |
| - "filter[category_name]": "uncategorized", |
51 |
| - "filter[posts_per_page]": 5, |
52 |
| - "filter[orderby]": "date", |
53 |
| - "filter[order]": "desc", |
54 |
| - "filter[post_status]": "publish" |
55 |
| -}); |
56 |
| -
|
57 |
| -$wpApiPosts.$get(id); |
58 |
| -
|
59 |
| -# DOES NOT WORK FOR NOW |
60 |
| -$wpApiPosts.$create(); |
61 |
| -``` |
62 |
| - |
63 |
| -### Media ```$wpApiMedia``` |
64 |
| - |
65 |
| -``` |
66 |
| -$wpApiMedia.$getList(); |
67 |
| -$wpApiMedia.$get(id); |
68 |
| -
|
69 |
| -# DOES NOT WORK FOR NOW |
70 |
| -$wpApiMedia.$create(); |
71 |
| -``` |
72 |
| - |
73 |
| -### Users ```$wpApiUsers``` |
74 |
| - |
75 |
| -Requires [authentication](http://wp-api.org/guides/authentication.html) |
76 |
| - |
77 |
| -``` |
78 |
| -$wpApiUsers.$getList(); |
79 |
| -$wpApiUsers.$get(id); |
80 |
| -$wpApiUsers.$getMe(); |
81 |
| -
|
82 |
| -# DOES NOT WORK FOR NOW |
83 |
| -$wpApiMedia.$create(); |
84 |
| -``` |
85 |
| - |
86 |
| -### Taxonomies ```$wpApiTaxonomies``` |
87 |
| - |
88 |
| -``` |
89 |
| -$wpApiTaxonomies.$getList(); |
90 |
| -$wpApiTaxonomies.$get(taxonomy); |
91 |
| -$wpApiTaxonomies.$getTermList(taxonomy); |
92 |
| -$wpApiTaxonomies.$getTerm(taxonomy, id); |
93 |
| -``` |
| 8 | +<http://shprink.github.io/wp-api-angularjs/> |
94 | 9 |
|
95 | 10 | ## Contribute
|
96 | 11 |
|
97 | 12 | ```
|
98 |
| -sudo npm install webpack webpack-dev-server -g |
99 | 13 | npm install
|
100 |
| -webpack-dev-server |
| 14 | +
|
| 15 | +# Open two terminals |
| 16 | +# and run watch to build on the lib files changes |
| 17 | +npm run watch |
| 18 | +
|
| 19 | +# in the other terminal run following to build the test page and the doc |
| 20 | +npm run devserver |
101 | 21 | ```
|
102 | 22 |
|
103 |
| -Open ```http://localhost:8080/test.html``` |
| 23 | +Open ```http://localhost:8080``` |
0 commit comments