angular-resource

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

拜拜、爱过 提交于 2019-12-14 03:39:47
问题 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

Why are my requests to web.api being blocked by long running controller code?

情到浓时终转凉″ 提交于 2019-12-13 17:20:50
问题 I'm working on my local development environment using angular to issue ajax calls to Web.API (IIS 8.5 hosted). I'm making 5 calls via different angular controllers simultaneously, each of which look like this: $scope.medications = API.Client.MedicationProfiles.query({ clientId: clientId }); The API service has this definition for the Client.MedicationProfiles resource: this.Client.MedicationProfiles = $resource( '/Noteable.API/api/Client/:clientId/MedicationProfiles/:id', { clientId: '

$resource success callback returning $promise

空扰寡人 提交于 2019-12-13 15:23:53
问题 Using Angular 1.2.14, $resource's success callback should return an object, but it sometimes gets a $promise. The node/express web service is returning null, but Angular interprets it as a $promise. When a non-null is returned from the web service, the success callback gets the object as expected. $resource('/api/users/:userId/team').get({ userId: userId }, function(team) { console.log('team: ', team); }, function(err) { console.log('err: ', err); }); The value of team (the parameter to the

angular resource not invoking my error callback function

試著忘記壹切 提交于 2019-12-13 14:06:09
问题 I've been at this for hours and I can't figure out why angular is not triggering my error call back when my rails back-end raises a proper error. I'm using angular 1.2.0rc1. According to the documentation: non-GET "class" actions: Resource.action([parameters], postData, [success], [error]) And I'm using it in my angular controller during a save product operation: $scope.saveProduct = function(product){ if (product.id) { Product.update({id: product.id},{product: product}, function(data){

Angular JS Fails After Upgrade from 1.1.0 to 1.1.1

独自空忆成欢 提交于 2019-12-13 11:50:53
问题 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

Angular $resource POST/PUT to WebAPI 405 Method Not Allowed

…衆ロ難τιáo~ 提交于 2019-12-13 04:35:15
问题 I wasn't able to find helpfull answer to the following problem. Angular $resource POST/PUT (both) generate 405.0 - Method Not Allowed error on a simple WebAPI calls. Get works just fine. App is an MVC with WebAPI running in IIS 7.5. When I try to run a sample locally - works fine. It's not a CORS issue and Auth was stripped out. PUT http://portal.local.com/api/products/5 405 (Method Not Allowed) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1

Using ngCsv with an external API

删除回忆录丶 提交于 2019-12-13 02:16:38
问题 So I have an external API which I'm trying to access and extract the data in it using JSONP and $resource service. I want to have a button from ngCsv which makes the request then when the data request completed exports the array to a csv file. but when I click the button it saves an empty csv file because the request takes about 11s to complete. I want to click the button and when the data was ready and received completely, export the csv file. Here's my app.js // Initializing Application

Run AngularJS resource tests without mocking responses

徘徊边缘 提交于 2019-12-13 01:13:39
问题 I'm using karma, mocha and chai to write tests for the resources in my AngularJS project and everything works great. Today, I'm using $httpBackend to mock every response when the resources are doing http requests. I wonder, however, if I would be able to run the tests without mocking the responses and testing out the real backend integration. Can't seem to find any way to do this. 来源: https://stackoverflow.com/questions/30346214/run-angularjs-resource-tests-without-mocking-responses

Angular $filter not updating variable on array returned by $resource

大憨熊 提交于 2019-12-12 05:28:42
问题 Say I've got an Angular $resource that returns an array of entries that all have a name attribute. I would like to use $filter in Javascript ( not using Angular's {{ blah | filter:filter }} syntax within the templates) to extract a subset of those entries based on the attribute. The code would look something like: app.controller('AppController', function ($scope, Project, $filter) { $scope.entries = Project.query(); $scope.entry = $filter('filter')($scope.entries, {name: 'Bar'}); ... }

Testing $resource without mock

橙三吉。 提交于 2019-12-12 01:39:11
问题 I'm trying to test the asynchronous $resource service by Angular. Firstly note that I don't want to mock $resource, I actually want to get the results and test them. So basically my getCountries method just uses Angular's $resource to return an array of countries. Method getCountries(): any { var countries = this.$resource( this.apiEndpoint.baseUrl, { 'get': { method: 'GET', isArray: false } }); return countries; } In my spec I'm having trouble with where to run Jasmine's done() method.