Page 187 - AngularJS权威教程
P. 187

16.8 和 MongoDB 通信   167


                  为了保证完整性,下面是完整的配置代码:                                                                1

                  angular.module('myApp', ['restangular'])
                  .constant('apiKey', 'API_KEY')
                  .config(function(RestangularProvider, apiKey) {                                    2
                  RestangularProvider.setBaseUrl('https://api.mongolab.com/api/1/databases/YOURDB/collections');
                      RestangularProvider.setDefaultRequestParams({
                          apiKey: apiKey                                                             3
                      });
                      RestangularProvider.setRestangularFields({
                          id: '_id.$oid'
                      });                                                                            4
                      RestangularProvider.setRequestInterceptor(function(elem, operation, what) {
                          if (operation === 'put') {
                              elem._id = undefined;                                                  5
                              return elem;
                          }
                          return elem;                                                               6
                      });
                  });
                                                                                                     7


                                                                                                     8



                                                                                                     9


                                                                                                     10


                                                                                                     11



                                                                                                     12


                                                                                                     13


                                                                                                     14



                                                                                                     15


                                                                                                     16


                                                                                                     17


                                                                                                     18
   182   183   184   185   186   187   188   189   190   191   192