Search Posts

Category: restangular

How to set multiple baseURL using restangular in angularjs

below code is my app.js file, and my problem is i have declared multiple port number(base URL) its working fine. app.config(function (RestangularProvider) { RestangularProvider.setBaseUrl(‘http://localhost:8086/mmg/api/v1/’); RestangularProvider.setDefaultHeaders({ “X-API-KEY”: “MMGATPL”, “Content-Type”: “application/json”, }); }); app.factory(‘FirstRestangular’,[ ‘Restangular’,function (Restangular) { return Restangular.withConfig(function(RestangularConfigurer) { RestangularConfigurer.setBaseUrl(‘http://localhost:8085/mmg/api/v1/’); RestangularConfigurer.setDefaultHeaders({ “X-API-KEY”: “*******”, “Content-Type”: “application/json”, }); }); }]); How should i declare base URL in route.js app.config(function (RestangularProvider, $stateProvider, $urlRouterProvider) { RestangularProvider.setBaseUrl(‘http://localhost:8086/mmg/api/v1/’); }; I can set only one base URL, if i declared multiple URL its […]

How to set a Restangular fallback url?

I have an angularJS application which uses Restangular to define the URL for the web services. function restangularProviderConfig(RestangularProvider) { RestangularProvider.setBaseUrl( ‘http://myapi.com.ni/’); } I have been requested that, if the URL is unavailable, the application have to use a fallback URL, for this example, fallback URL would be: http://myapi.app Is there any way to set restangular to have a fallback URL for when the previously set URL fails? Source: AngularJS

Weird console.log behavior, incomplete objects

I have an Angular service that is using Restangular to send a GET request to my backend and get the response, I’m using Restangular.one(‘/users/3′).get(). In the then block I’m just returning property result of Restangular’s response object. The problem lies here, the user returned have a property additional_properties, but actually any code using the service finds this property empty!! Although it is NOT empty when examined at the network tab. When console.log-ing the object, I […]

Pass json with special characters angularjs to ruby

I need to make a search form, where the back end used is ruby and front end as angular. the search query is generated in angular in json format and is passed to ruby via restangular service. Its working fine. But when we tested the search string with semicolon it returned 500 Internal error. the puts params[:search] gives {“content”:”my search is ; for the actual json string is {“content”:”my search is ; and :”, “options”:[]} […]

Restangular POST returns empty parentResource

I don’t know if I understood very well, but what I guess is that when you post with a previous Restangular element that came from server, it should result in a restangular element with the first element as parentResource. Take a look at this code: // GET: api/vessels var vessels = Restangular.all(‘vessels’).getList(); this.vessel = vessels[0]; // POST: api/vessels/125/events this.vessel .post(‘events’, event) .then(event => { // the server returns the same object but with id filled […]

Restangular interceptor to handle $q.all request

I need help for Restangular interceptor. i can retry request all of the failed API calls but the data was not returned to the success method of the calling function. When not using $q.all, the interceptor was working fine. I need help how can I return the data. Below is my code for the interceptor: authrestangular.factory(“AuthRestangular”, function (Restangular, $q, $injector, $location, localStorageService, $filter, $timeout, cfpLoadingBar, $cookies) { return Restangular.withConfig(function(RestangularConfigurer) { RestangularConfigurer.addFullRequestInterceptor(function (element, operation, route, url, […]

AngularJS restangular post callback

I am using restangular with AngularJS, and I need to use some function, which will trigger callback function/promise after POST response. I tryed setResponseInterceptor which did not helped in this situation. I need to use this function to lock form from submission until response will come back to client, and then unlock it to future use. Do you know some magic for this? I am using this code, and want to fire custom function when […]

Wait for authentication response from server before executing any Angularjs app

I have an AngularJS app (bootstrapped using ng-admin) contained within an admin backend where initial login to it is handled via LDAP. When the Angular app loads for the first time, it needs to make an API call (using Restangular) to the server to fetch a token plus derive a separate API url to use. Once the token is returned, it’s stored in localStorage and then passed to all subsequent API calls. Because I’m not […]