angular-resource

How do I remove the default headers just for specific XHR requests in AngularJS?

六月ゝ 毕业季﹏ 提交于 2019-12-05 00:42:15
99% of my ajax calls need a specific "X-API-TOKEN" to authenticate and communicate with my Rails REST API. But I'm also making a call to one thrid party API and I keep getting an error saying "Request header field X-API-TOKEN is not allowed by Access-Control-Allow-Headers." Everything works fine if I delte the header right before the call, and a work around would be to delete and then re-add after the call, but is there an easier way than this: apiToken = $http.defaults.headers.common["X-API-TOKEN"] delete $http.defaults.headers.common["X-API-TOKEN"] $http( method: "GET" url: 'http://...}}' )

Angular Resource Encoding URL

拟墨画扇 提交于 2019-12-04 03:54:59
I have a resource defined as follows: app.factory("DatumItem", function($resource) { return $resource('/data/:id', {id: '@id'}); }); In my view I have: <div ng-click="go('/datum/' + d.to_param)">Test</div> where go() is defined in my controller as: $scope.go = function (params) { $location.path(params); }; For the item in question, d.param is equal to TkZUOWZwcnc9Uldo%0ASzRvd2FiWk But when I call DatumItem.get() with the correct ID, it is changing the id to TkZUOWZwcnc9Uldo%250ASzRvd2FiWk Is there a way to prevent the % from being encoded to a %25 in this case? I've tried a combination of

angularjs handling $resource $promise errors

瘦欲@ 提交于 2019-12-03 20:18:49
Could somebody help me figure out how to return hard-coded data in my AngularJS factory if there is an error connecting to my API. My hard-coded data are located in another factory called "dataFactory". Appreciate the assistance. service.factory("ScheduleFactory", ['$http', '$resource', '$q', 'dataFactory', function($http, $resource, $q, dataFactory) { var objFactory = {}; objFactory.getDaysOfWeek = function(includeWeekends) { var days = []; var API = $resource(restURL + '/daysOfWeek/'); API.query() .$promise .then(function(data) { isEmpty = (data.length === 0); if (!isEmpty) { days = data; };

Angular JS Fails After Upgrade from 1.1.0 to 1.1.1

守給你的承諾、 提交于 2019-12-03 16:55:56
When I upgrade the the ng-repeat takes extraordinarily long to load and tries to display MORE content boxes without the content that is being served by $resource. I have narrowed the problem down to the update between 1.1.0 and 1.1.1. I looked through the changelog but nothing popped out at me to be the culprit, but it must be in there. Changelog => https://github.com/angular/angular.js/blob/master/CHANGELOG.md#111-pathological-kerning-2012-11-26 The repository for this app => https://github.com/brianpetro/resume Currently my angular looks like: app = angular.module("Resume", ["ngResource"])

Rails duplicated the parameters inside the resource

£可爱£侵袭症+ 提交于 2019-12-03 15:22:55
问题 I am using the Angular Resource and I don't understand why Rails duplicated the parameters and put it inside the resource name. I just need to understand why this is happening. // post data {"title":"asdsad"} // rails parameters Parameters: {"title"=>"asdsad", "presentation"=>{"title"=>"asdsad"}} Duplicate because welcome to Stackoverflow where you need 50 points to comments so this happen. I really so sorry: AngularJS $resource sending out an extra "registration" hash? 回答1: ..if you've

How to configure Angular $resource (ngResource) to pull data from another domain using CORS

你。 提交于 2019-12-03 14:09:24
I'd like to be able to setup resources using $resource using CORS to request my data. I've got CORS working with $http but the same techniques don't apply to $resource and I was hoping someone can come to my rescue and show me how with $resource. I've modified the last step of the Angular tutorial to use CORS by hacking the phonecatServices service, in the services.js file. I found this example which uses the $http.defaults.useXDomain = true; delete $http.defaults.headers.common['X-Requested-With'];line to get angular to request the data using CORS but if I try $resource.defaults.useXDomain =

Angular js way to download file and show loading screen using the $resource

喜你入骨 提交于 2019-12-03 13:09:41
I am using Angular js to show loading screen. It works for all the REST services call except REST service to download the file. I understand why it is not working because for download I am not making any service call using $resource; instead of that I am using normal approach to download the file therefore Angular js code doesn't have any control on start/finish the service request. I tried to use $resource to hit this REST service however I am getting the data from this service and in this case loading screen was working fine however not sure how to use this data to display to user to

Rails duplicated the parameters inside the resource

我们两清 提交于 2019-12-03 05:54:44
I am using the Angular Resource and I don't understand why Rails duplicated the parameters and put it inside the resource name. I just need to understand why this is happening. // post data {"title":"asdsad"} // rails parameters Parameters: {"title"=>"asdsad", "presentation"=>{"title"=>"asdsad"}} Duplicate because welcome to Stackoverflow where you need 50 points to comments so this happen. I really so sorry: AngularJS $resource sending out an extra "registration" hash? ..if you've turned on config.wrap_parameters in your initializer [check the file config/initializers/wrap_parameters.rb] or

AngularJS - Using $resource.query with params object

风流意气都作罢 提交于 2019-12-03 03:38:28
问题 I'm trying to pick up angular.js and working on figuring out some of the things that are a bit less documented. Consider this - I have a search method on the server that accepts query params and returns a collection of search results, and responds to GET /search.json route (Rails FWIW). So with jQuery , a sample query would look like this: $.getJSON('/search', { q: "javascript", limit: 10 }, function(resp) { // resp is an array of objects: [ { ... }, { ... }, ... ] }); I'm trying implement

AngularJS - Using $resource.query with params object

一世执手 提交于 2019-12-02 17:58:43
I'm trying to pick up angular.js and working on figuring out some of the things that are a bit less documented. Consider this - I have a search method on the server that accepts query params and returns a collection of search results, and responds to GET /search.json route (Rails FWIW). So with jQuery , a sample query would look like this: $.getJSON('/search', { q: "javascript", limit: 10 }, function(resp) { // resp is an array of objects: [ { ... }, { ... }, ... ] }); I'm trying implement this using angular, and wrap my head around how it works. This is what I have now: var app = angular