FAQ Database Discussion Community


Angular-poller doesn't work on IE11 when the development tool is not opened

javascript,angularjs,internet-explorer-11,angular-resource,ie11-developer-tools
I am working on an angular v1.3 app and I am using angular-poller in one my controllers to automatically send request to get new data from my backend every 2 seconds. It works fine in Chrome, but does not work in IE11. But strangely enough, I am using the Fiddler...

How to reduce code redundancy when defining routes in AngularJS

angularjs,rest,angular-resource,angular-routing
I am currently coding a Rest API and a client in AngularJS. I am using the Angular modules angular-resource (ngResource) angular-route (ngRoute) This is how my routing configuration looks like: $routeProvider .when('/facility', { templateUrl: pathTemplate + 'Facility/index.html', controller: 'FacilityIndexController', resolve: { Facilities: ['Facility', function(Facility) { return Facility.query(); }] } })...

How to access raw JSON string of ngResource response?

angularjs,angular-resource
I use ngResource to query a JSON service and per default Angular parses the response. Unfortunately I'd also like to have access to the raw response string. Here is a snippet of what I'd like to achieve: var app = angular.module('plunker', ['ngResource']); app.factory('DateResource', function($resource, $http) { var raw = null,...

Web API CORS Angular $resource

cors,asp.net-web-api2,angular-resource
I have a Web API constructed in VS2012 using MVC4 and Web API 2. The front end is developed in AngularJS using ui-grid. The VS2012 JavaScript editor is not really very friendly, so I am using JetBrains WebForm 9 to develop the front end. This means that every request to...

Select some data and then persist to next controller/view in Angularjs

angularjs,angularjs-ng-repeat,angular-ui-router,angular-resource
I am bringing in some simple data via a service that uses angular-resource like so: angular.module('InvoiceService', ['ngResource']) .factory('InvoiceService', function ($resource) { return $resource('data.json'); }) .controller("DashboardListCtrl", function (InvoiceService) { var vm = this; InvoiceService.query(function (data) { vm.invoices = data; }); vm.submit = function (form) { console.log(form) }; }); And the html:...

Get specific fields using an Angular $resource

angularjs,angular-resource
Is there a way to get specific fields with an Angular $resource? Without creating a new REST endpoint that specifically returns the fields I care about? For example, let's say I have a Person $resource and it is bound to a REST endpoint where GET returns the full Person object....

Saving subresource with Angular's $resource

angularjs,angular-resource
I have a factory defined which returns a $resource: myApp.factory('Region', function($resource) { return $resource(baseUrl + '/templates/:templateId/regions/:regionId', null, { query: { method: 'GET', isArray: false }, update: { method: 'PUT' } }); }); As you can see, a region is a subresource of a template, and I've defined the endpoint as...

AngularJS: Issue with interceptors in $resource

angularjs,angular-resource
Im having a weird behavior manipulating a response through $resource with a custom interceptor. If I use a response interceptor like this : angular.module( 'app.services', [] ) .factory( 'Product', function( $resource, routesConfig ) { return $resource( routesConfig.catalogueEndPointg(), {}, { query: { method :'GET', isArray : false, params : { page...

Using GET only reqeusts on API - $http or $resource

angularjs,angular-resource,angular-http
If all I am doing is making basic GET requests from an API (not full CRUD), is it better to use $http or $resouce? I see that $resouce uses $http under the hood so does that make it overkill? Code is written more streamlined using $resouce than $http espcially when...

Access to header information by $resource in AngularJS

angularjs,http-headers,authorization,angular-resource
I send a request server-side by $resource which is inside my factory. In the return object there many information, but I'd like to have access to the authorization in the headers. I tried to print the returning object by console.log() but I dont see any headers and authorization in console....

AngularJS constants in main module

angularjs,constants,angular-resource
It looks like there's several ways to define constants in Angular. In this example we are defining two constants in our main module config.js: 'use strict'; angular.module('app') .constant('URL', 'http://localhost:8080/users') .constant('RESOURCES', (function () { var resource = 'http://localhost:8080'; return { USERS: resource + '/users' } })); }()); We have a factory...

Unknown Provider Error while trying to test generic angularjs $resource service

angularjs,testing,jasmine,angularjs-service,angular-resource
I have generic service that create resources for my application: (function(module) { module.provider('restService', { resourceRegistry: {}, addRestResource: function(entityName, entityProto) { this.resourceRegistry[entityName] = entityProto; }, $get: function() { var restService; for (var entityName in this.resourceRegistry) { createRestResource(entityName, this.resourceRegistry[entityName]); }; restService = { //createRestResource: createRestResource }; return restService; }}); function createRestResource(entityName, entityProto)...

service method does not recognize variable defined outside

javascript,angularjs,angular-promise,angular-resource
Here is a service: angular.module('core').factory('ServerErrorAlert', ['toaster', function(toaster) { return function(errorResponse) { toaster.pop('error', 'Error', errorResponse); if (deferred) { deferred.reject(errorResponse); } } } ]); Here is how I call it : function update(updatedTransaction, originalTransaction, updateLocal) { var deferred = $q.defer(); updatedTransaction.$update(function() { if (updateLocal) {angular.extend(originalTransaction, updatedTransaction);} deferred.resolve(updateLocal ? originalTransaction : false); }...

Request changed from POST to OPTIONS hangs

angularjs,cors,angular-resource
I am trying to send a POST request to an endpoint over HTTPS. The request has 2 headers, content-type (application/json) and an apiKey. I am using the request in a PhoneGap application built in Angular, and when the request is sent its method is changed to OPTIONS. I know this...

Using $resource.query, I want to return an object that contains an array of the actual resource

angularjs,angular-resource
By default, the $resource.query() is set up to expect an array of objects that become $resource objects. To accommodate paging in a nice, restful way, I have my GET /api/widgets endpoint set up to return the following object: { currentPage: 1, perPage: 20, totalItems: 10039, items: [{...}, {...}, {...}] }...

AngularJS resource query is misinterpreting object composed by arrays

php,angularjs,api,angular-resource
I have the following resoure: var get = $resource('http://localhost/', {}, { query: { method: 'GET', headers: { 'Content-Type': 'application/json' }, params: { 'a': [10, 20, 30] } } }); My problem is that AngularJS is translating this into a call for this url: http://localhost/api?a=10&a=20&a=30 On the other end (http://localhost/api), I...

Angular : intercept specific request with $resource

angularjs,interceptor,angular-resource
I'm new to Angular, and am working on an interceptor. I created an angular factory to get some data from an API like that : app.factory('Connection',['$resource',function($resource) { return $resource('url',{param1: '1',param2: '55'},); }]); I also created the interceptor which looks like that : app.factory('connectionInterceptor', function($q,$location) { var connectionInterceptor = { response:...

Passing Data vs. Separate Request in AngularJS using ngResource

angularjs,angular-resource,ngresource
I'm new to angular and trying to figure out how best to accomplish this. Say you have set up an ngResource factory to get a bunch of widgets . You return those widgets(GET /api/widgets) and display them on the page in a list. Now say you can edit those widgets...

Doing a GET passing a complex object with angular

angularjs,get,angular-resource,complextype
I am using AngularJs and Resources module. I want to do a GET to obtain an object.. to do this GET I do not have to pass simply the ID to the server, but I should pass a complex object with different properties and values.. Here the code I am...

Object field becomes null while doing a put in angularjs

angularjs,angular-resource
I've run into a strange issue, where when I do a PUT using angular $resource, a field for a newly added object becomes null. The data is a bunch of nested objects. When the user drags a list item to another list, that item is pushed onto the associated object...

Trying to resolve API call with a factory and $resource, but I'm stuck on returned object

angularjs,angularjs-directive,angular-ui-router,angular-resource
I'm a beginner programmer and beginner with Angular, so forgive any obvious mistakes. I've been banging my head against this for hours, and realized it's time to ask for help. I have an API that is returning an array of objects with two key/value pairs: ClientName and ClientDivision I have...

angular $resource factory pass parameter

angularjs,factory,angular-resource
I have a factory that makes some $resource calls to the server. The setData function works fine. My question is how do I pass a parameter into the factory to be used in the SubmitAttendance function? I need to pass a id to be sent to the server .factory('AttendanceData', function...

Angular JS service dependency injection error

angularjs,angularjs-directive,angular-resource,angular-services
I am new to angular I have been trying to do asynchronous validation for username availability and I am getting "Cannot read property 'userName' of undefined" Here is my service code webAppServices.factory('services', ['$resource', function ($resource){ return{ users: $resource('http://localhost:8080/api/users',{},{ get:{method:'GET',isArray:true}, add:{method:'POST',isArray:false}, update:{method:'POST',isArray:false} }), userName:$resource('http://localhost:8080/api/users/check/:username',{},{ check:{method:'GET',isArray:false} }) };}]);...

How to send objects with arrays using angular resource?

angularjs,angular-resource
I have a product object with a property called category_ids that is an array of ids. I've added an $update method to my resource factory so I can send a PUT request. When I PUT, the server receives data that looks like: id: 1, description: 'Yada yada', category_ids: [1,2,3], product:...

Angularjs service call from $rootscope causes unending iterative loop

javascript,angularjs,sharepoint,angular-resource
I'm fairly new to the ng-world so please go easy on my noobness :) I've really tried to keep to the "angular" way of thinking in organizing my code and understanding it's dependency injection IoC methodologies. One of my goals is dealing with REST services in SharePoint. The SharePoint integration...

How to loop through $resource returned query and get desired value?

angularjs,angular-resource,meanjs
I am using MEANJS In my controller i have // Find a list of Cars $scope.findHome = function() { $scope.cars = Cars.query(); console.log($scope.cars); }; Which outputs here i want to get the _id string inside the first array 0: Resource I tried $scope.cars[0]._id which returns undefined, Please help....

Angular ngResource handle 404 api error

ruby-on-rails,ajax,angularjs,api,angular-resource
i have a Rails API Ex. example.com/v1/portfolio/{{ id }} and i'm using AngularJS ngResource to handle the data with get. myAppServices.factory('Portfolio', ['$resource', function($resource){ return $resource('api/v1/portfolios/:id/', { id:'@id'}, { query: { method:'GET', params:{id:'@id'}, isArray:true } }); }]); How can i handle the Not found 404 Error if the API does not...

Aborting ngResource using a promise object

javascript,angularjs,angular-promise,angular-resource
I've recently learned that ngResource request can be aborted either by specifying a timeout in ms or passing a deferred object. The second solution does not seem to work for me, and I have no idea what I'm doing wrong. I've created a fiddle to demonstrate the problem http://jsfiddle.net/HB7LU/10977/ var...

Angularjs - Abort/cancel running $http calls

angularjs,autocomplete,angular-resource,angular-http
I've got a call using Resource in angularjs but i get some problems because i can't abort every calls it does. This kind of structure i use for an autocomplete.. is it possible convert from resource call to http? This is the code var Resource = $resource(URL, {},{ getAutocompleteResults: {...

How to access response headers using $resource in Angular?

angularjs,http,angular-resource
I basically call get requests like so: var resource = $resource('/api/v1/categories/:id') resource.get({id: 1}).$promise.then(function(data){ console.log(data) }) This works fine.. but how do I get the response headers?...

Populate ng-flow with jpeg/jpg as blob

javascript,angularjs,blob,angular-resource,ng-flow
I'm currently trying to populate ng-flow with images from my webserver(nodejs http-server), and I found this thread: Populating image files with ng-flow.js from json As you can see in the answer from Aidas, he says that you need to add the data to a blob and then use addFile(blob) But......

Nested/embedded $resources in ngRepeats

angularjs,angularjs-ng-repeat,angular-ngmodel,angular-resource
My API populates some nested models. Using a shopping example, when you query orders, the items property is populated with the description and quantity instead of returning just the item IDs. orders: [ {_id: 1, items: [ {_id: 100, description: "apple", // from lookup in the Items table quantity: 4...

Angular JS Sending Array data with $resource to .NET API

.net,angularjs,api,angular-resource
Yes, I know there is a gazillion posts about sending array data using angular $esource. I read this, this, and pretty much the top 10 google results on this topic, but I still can't make it work. I suspect that it might have to do with the server side API,...

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

javascript,c#,angularjs,asp.net-web-api,angular-resource
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...

AngularJS convert Date to getTime() before sending to server

javascript,angularjs,angular-resource
I have a form that uses <input type="datetime-local" ng-bind="course.endDate".. and sets a variable of the model. Before sending the date to the server I've to convert the date 2015-04-04T22:00:00.000Z to a integer given by the getTime(). In the controller i added this: course.endDate = course.endDate.getTime(); it works for the server...

Manipulate collection returned from $resource

angularjs,angular-resource
I have a service called Message that returns messages from an API. It simply looks like this: app.factory('Message', function($resource) { return $resource('http://localhost:3000/messages/:id'); }); It works fine, and I use it in my controller to assign messages to my scope: app.controller('MessagesCtrl', function($scope, Message) { $scope.messages = Message.query(); } When I log...