Menu
  • HOME
  • TAGS

Cannot bind ngResource to ngOptions

angularjs,ng-options,ngresource

Here's a working JsFiddle from your other question, demonstrating the returned data from there. <select ng-model="selected" ng-options="d for d in data"></select> JS: function MyCtrl($scope) { MyCoolResource.query(function(result){ $scope.data = result; }); } ...

angularjs: show container only after $resource.query result returned

angularjs,ngresource

It looks like the problem is related to using jQuery and Angular together. In short, Angular uses "digest cycles" to update the screen. So when jQuery does it's thing Angular doesn't know about it. The slideDown() function takes two arguments. The first is a duration of the slide animation, the...

AngularJS and Basic HTTP Auth

javascript,json,angularjs,http-basic-authentication,ngresource

No 'Access-Control-Allow-Origin' header is present on the requested resource. If you say you haven't changed the front-end code since the last time you touched it, then that can only mean that something on the server changed... Based on the error you've provided, it seems like a pretty clear case of...

Understanding angularJS $resource isArray property

angularjs,ngresource

I think you have misunderstood the documentation. By default without adding any custom actions, the following are supported: 'get': {method:'GET'}, 'save': {method:'POST'}, 'query': {method:'GET', isArray:true}, 'remove': {method:'DELETE'}, 'delete': {method:'DELETE'} So by default the query action expects an array to be returned which makes sense since a query generally would return...

How can I update the $scope in AngularJS when a server sided update occurs?

angularjs,cakephp,websocket,ngresource,ratchet

You just need to read events from the WS and populate them using $emit and $broadcast, then your controllers can subscribe to whichever events are relevant to them. Take a look at: angular websocket factory AngularJS and WebSockets beyond...

Using $resource.query on an array of objects

angularjs,ngresource

Ah, this was always one of my biggest headaches when working with $resource! The problem is that $scope.products = productService.query(); is asynchronous. What this means is that $scope.product will be set to something that does not exist yet. that is, the code skips over .query() straight to that line. What...

ngRepeat not updating even though $resource has

angularjs,angularjs-scope,angularjs-ng-repeat,ngresource

As I said in OP, this was a very basic scope error as I forgot I was actually switching the ui-router view between the two actions so my $scope.users were actually two different things. Moving the list to $scope.$parent.users fixes it for now, though thinking about it again I should...

AngularJS ng-switch before load

javascript,angularjs,ngresource

The reason this is happening is because the $resource service returns an empty object that is asynchronously filled after the requested data is obtained. To solve this: Assign the requested data from a non $scope variable. Create a function callback in the query() action. Assign the non $scope variable in...

Using locale in the $resource URL

angularjs,locale,ngresource

Just provide a function that returns your value (see documentation): $resource('/:localeId/...', { localeId: function () { return $locale.id; }, // ... }) ...

Extracting data from angularJS $resource

angularjs,rest,ngresource

You are not handling the promise that $resource hands back. It needs to be handled like your $http call above. var Topic = $resource('http://api.discussorama.com/v1/topics/id', { id: '@id'}, { query: { isArray: false, method: 'GET', headers: {'X-Api-Secret': 'xxx', 'Authorization': 'xxx', 'Content-Type': 'application/x-www-form-urlencoded'} } }); var response = Topic.query(); response.$promise.then(function(data){ $scope.topics =...

How do you send a POST request for logging in, with Angular's $resource?

angularjs,http,ngresource

After defining your resource, you can use the save method which is default action for post defined by $resource. The first parameter of save takes arguments used as url params, and the second parameter takes post data. var LoginResource = $resource("/rest/path/login"); var bodyObject = {username:"test", password:"test"}; LoginResource.save({}, bodyObject); Then you...

AngularJs show Error: [$injector:modulerr] in console?

angularjs,ngresource,ngroute

You can't inject $scope during configuration phase. Configuration blocks - get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured. You can't inject $routeProvider in controllers...

How to call my factory service correctly?

javascript,angularjs,ngresource

It's probably because you're passing your actions in where the default params go. Change it to Customizing: $resource(url, {valid: true}, { squares: // etc I used valid: true as the default params as you appear to use it in both actions....

angularjs infinite request loop for $resource

javascript,node.js,angularjs,ngresource,ngroute

It turns out my client side route needed to be $routeProvider.when('/courses/:id', { templateUrl: '/views/courses/details', controller: 'CourseDetailsCtrl', }) One missing / in the templateUrl path...

AngularJS - initialize ngResource object if API response is null

angularjs,ngresource

Wrap it on a function that you can call as many times as you like. module.factory('UserPreference', function($resource, $q) { var resouce = $resource('/users/:user_id/preferences/:preference_type_id', { user_id: "@user_id", preference_type_id: "@preference_type_id" }); return function (userId, preferenceTypeId) { var promise = $q.defer(); var defaultPreference = {user_id: 1, preference_type_id: 1, preference: null}; $q.when(resouce.get({user_id: userId, preference_type:...

how to wait until promise returns when using $resource

angularjs,angular-services,ngresource

well i guess the answer was very simple. i was missing 'return' in getNodes() so what worked for me is function getNodes() { $scope.nodes = nodeResource.query(); **return** $scope.nodes.$promise.then(function (response) { $scope.nodes = response; //other logic }); ...

IE9 resource returing array of char instead of JSON object

javascript,json,angularjs,internet-explorer-9,ngresource

I fixed it by doing the following: public JObject Get(string vid) { String result; var status = new { Rating = 100, UserRated = true }; result = JsonConvert.SerializeObject(status); return JObject.Parse(result); } seems there was a problem with the Jtoken, and by doing an explicit parse to JObject it ended...

angularjs $resource and one-to-many relationship

angularjs,ngresource

ngResource is great but doesn't 'really' handle relationships and might be lacking a few things you need. What you have proposed - "create a $resource for parent and child, and call save() on the child for each time a new related child is created, passing the parent_id" - would be...

confused between Api Controller and oData Controller to use with angular's ngresource

angularjs,ngresource,asp.net-web-api-odata

its look like i can use oDatacontroller with a model builder setup like this ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<StoreCommand>("StoreCommandsRest"); config.Routes.MapODataServiceRoute(routeName: "OData", routePrefix: "api", model: builder.GetEdmModel()); config.AddODataQueryFilter(); and all i needed to change was query to get $scope.totalCount = storeCommandResource.get({ $inlinecount: "allpages", $top: 0 }); then i am reading my...

angularjs ngResource success undefined

javascript,angularjs,ngresource

This worked for me: $scope.addNewStudent = -> Api.Student.save { student: $scope.newStudent}, ((successResponse, headers) -> console.log successResponse.id .... The solution was given here: handle error callback on save() method $ngResource...

ngResource makes a request but does not parse results

json,angularjs,rest,ngresource

The console.log() is getting called before the data arrives, because MyCoolResource.query() is asynchrone, try to use a callback that will be executed once the query ended and the data returned from the API then show this data via the console.log(): MyCoolResource.query(function(result) { console.log(result); }); ...

angularjs, ngResource in a factory and network calls

angularjs,ngresource

Depends, and yes. You will always need to handle it as a promise, and you can enable/disable the http cache. If you have the cache set to true, then the request will send off once and be cached until the cache is cleared. You can find more about the $resource...

handle error callback on save() method $ngResource

angularjs,ngresource

From https://docs.angularjs.org/api/ngResource/service/$resource: non-GET "class" actions: Resource.action([parameters], postData, [success], [error]) non-GET "class" instance: Resource.action([parameters], [success], [error]) $resource's save method falls into the non-GET 'class' instance category), so its error callback is the third argument. Your code would look like: $scope.save = function (params) { MigParams.save(params, function(resp, headers){ //success callback console.log(resp); },...

angular $resource methods dont send the right value

angularjs,ngresource

You should call: ProductData.delete(...) in the $scope.deleteProduct function

Virtual attributes in ngResource

angularjs,ngresource

You could try intercepting the response from the Person resource and augment the response. Like this: app.factory('Person', ['$resource', function($resource) { function getFullName(){ return this.name + ' ' + this.surname; }; return $resource('api/path/:personId', { personId: '@_id' }, { update: { method: 'PUT' }, 'get': {method:'GET', isArray:false,interceptor:{ 'response': function(response) { response.fullname =...

Problems with angular-ui-router - I cannot apply a filter to a repeat in a directive

javascript,angularjs,angular-ui-router,ngresource

It's a scope issue, your templates have their own child scopes that can't see values in each other, so when you set the personFilter.color in one template, your template using it as a filter doesn't know about it. You can use angularjs batarang or just insert a simple binding to...

Error in resource configuration. Expected response to contain an object but got an array

javascript,angularjs,ngresource

Change tileServiceCall.get(..) to tileServiceCall.query(...).

ngResource save() strange behaviour

angularjs,ngresource

Try something like this Module.factory("Discount", ["$resource", function ($resource) { return $resource(GLOBALS.apiPath + "discounts/:Id", { Id: "@Id" }, { somthingCustomIfNeeded: { method: 'POST', url: GLOBALS.apiPath + "something-custom" } }); }]); Notice the { Id: "@Id" } object? It tells Angular how to resolve that :Id variable Quote from documentation If the...

Passing Data vs. Separate Request in AngularJS using ngResource

angularjs,angular-resource,ngresource

I don't see a reason to fetch it again, I would just reuse the object.

Good example of a put operation using AngularJS $resource

angularjs,ngresource

If you're creating a new entity in your data store you want to use POST/save. If you're updating the data associated with an already existing entity in your data store you want to use PUT/update. Patch is usually reserved for when you just want to update a subset of the...

Retrieve associations in AngularJS & Rails using ngResource

ruby-on-rails,angularjs,ruby-on-rails-4,associations,ngresource

This isn't really an Angular issue, it's a Rails (and API design) issue. The reason I say API design is because depending on the use case it may be more efficient for the client to fetch all categories and do the work in the front end to match categories to...

Issues using $resource without the new operator

javascript,angularjs,ngresource

Try transport.getAll(...).$promise.then(...) instead. I know the difference between constructor function and usual function. But I don't understand why promise API works only in second case. well because the API is designed that way.You have instance methods and class methods. To create an instance you need the new operator and then...

AngularJs (ngResource ) : Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/

angularjs,ngresource

Typo in ngRessource it should be ngResource var myApp = angular.module('myApp', ['ngResource']); Also You made angular js script reference self closing which was totally wrong. you should close angular script tag properly. Look below. <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> ...

ngResource treating POST like GET

angularjs,post,save,factory,ngresource

The params keyword will resolve any route variable and the rest will be in the request query. To send values in the request body you can do: var user = new User( { cid: $stateParams.company_id, objEditUser: TempUserInfo }) ; user.$EditUser(); And change your resource to be something like: $resource('/api/User/:route', {},...

AngularJS $resource Custom Action for Requesting a Password Reset

angularjs,rest,ngresource,angularjs-1.3

yes, looks a little bit weird. Instead of GET I will use POST request to reset the password and pass the email param in request body

Uncaught Error: [$injector:modulerr] AngularJS

javascript,angularjs,ngresource

The ability to configure stripping of traling slashes was added in AngularJS 1.3.0-beta.6. Make sure you are not using an earlier version. The changelog of AngularJS can be found here....

angular resource clears object data after post

angularjs,ngresource

Here I found the answer to my problem: AngularJS - Prevent Form Clear Basically: call class method Device.save($scope.device) //.... instead of $scope.device.$save and it will presist the data you've in $scope.device class....

Multiple parameters in AngularJS $resource GET

javascript,angularjs,rest,ngresource

You can override url, Read $resource docs url – {string} – action specific url override. The url templating is supported just like for the resource-level urls. In resource declaration findRange:{ url: '/RMAServerMav/webresources/com.pako.entity.rma/:id/:to', method: 'GET', params:{ id:'@id', to: '@to' } } In Controller $scope.rmas = rmaService.findRange({id:0, to: 3}); ...

AngularJS - $resource + ng-repeat issue

javascript,angularjs,angularjs-ng-repeat,ngresource

Thanks for the answers. I have taken the closer look at which methods have been called in the backend. It is actually a rare server-side issue that messed up routing. ...

Angular ngResources request interceptor

angularjs,request,ngresource

You can implement your own interceptors as follows. app.config(function ($httpProvider) { $httpProvider.interceptors.push('myInterceptor'); }); app.factory('myInterceptor', ['$q', function ($q) { return { request: function (config) { config.headers = config.headers || {}; // insert code to populate your request header for instance return config; }, response: function (response) { if (response.status === 403...

So I have angular from bower, now what?

json,angularjs,module,bower,ngresource

There is a better way to do it! You could make use of --save option of bower to have the dependencies. For example you could have done: bower install angular --dev --save So that, the bower.json file is automatically updated by the bower and you don't have to touch it!...

id not captured by ngRoute

angularjs,ngresource,ngroute

you are using the @ property incorrectly in this case, and never actually passing your id to the resource. From the Angular Documentation: If the parameter value is prefixed with @ then the value for that parameter will be extracted from the corresponding property on the data object (provided when...

How does it make sense to use the variable name used to name a function inside that same function?

javascript,angularjs,ngresource

When you call User.get(), it returns a promise, and processing continues. When that promise resolves, angular sets the variable you set it to, in this case user, to the value of the resolution. It also calls the success callback function, so you can safely change it at that point. To...

Unable to hit my local API route in Express

angularjs,node.js,api,express,ngresource

I think it's the mismatch of trailing slash vs. no trailing slash between your angularjs code and your expressjs code. Try app.post('/api/accounts', accountsController.create);.

MEAN stack and ngResource - don't understand how to pass url resource ids

angularjs,express,mean-stack,ngresource

After the discussion in the comments I believe the presented have three problems: Question resource is defaulting the quizId to null, this will make your request look like: api/quizes/questions lets fix this by : return $resource('api/quizes/:quizId/questions/:questionId', { questionId: '@_id', quizId: '@quiz' }, { update: { method: 'PUT' } Then when...

How to return a promise with ngresource post

ajax,angularjs,promise,angular-promise,ngresource

Resource instances have a $promise attribute, they are not promises themselves. Just prefix your then call with $promise. var promise = DocumentLocation.save(model); promise.$promise.then(function success(model) { .... ...

ngResource and Json API spec

angularjs,ngresource

Look into transformResponse and interceptor objects. https://docs.angularjs.org/api/ngResource/service/$resource EDIT: Adding code $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) { return { 'response': function(response) { response.data = response.data.data; return response; } }; }); $httpProvider.interceptors.push('myHttpInterceptor'); ...

Angularjs Rest endpoint with username password

javascript,angularjs,rest,curl,ngresource

If you are sending response in the format of 'application/x-www-form-urlencoded' the actual data format should be the same. What you are sending currently is a JSON object. You would need to use $http tranformer to tranform the request: Something in line of transformRequest: function (data) { var postData = [];...

POST parameter to web api being set as null

javascript,c#,asp.net,asp.net-web-api,ngresource

Though I'm not sure what causes the string to be null in the controller, instead of posting a string to the Web API controller you could send an object wrapping up the string instead and that would be accepted correctly.

Web Api 2 with two method with the same HTTP verb an angularjs resources

angularjs,rest,asp.net-web-api2,ngresource

Here is some explanation about a the REST Endpoints. In REST we are manipulating ressources. As collections or individual. Classics endpoint would be : GET /rest/houses DATA : none -> will return a collection of houses GET /rest/houses/{id} DATA : none -> will return the house find by its {id}...

Working example of AngularJS $resource searching items in Web Api

c#,angularjs,asp.net-web-api,ngresource

You're going to need a custom model binder. From what I understand FromUri will not handle complex nested types or json which $resource will put in the query string. Github Sample Model binder: public class CriteriaModelBinder : IModelBinder { public bool BindModel( HttpActionContext actionContext, ModelBindingContext bindingContext ) { if (bindingContext.ModelType...

How to pass dynamic param in angular $resource

javascript,angularjs,ngresource

This should help you. app.factory('myFactory', ["$resource", function($resource) { return $resource('http://google.com', {}, { query : { method : 'GET', isArray : true, params : { ts : Date.now } // <-- new timestamp will be genrated and assigned to ts } }) }]); each time you invoke myFactory.query() method a querystring...

Can't get only the header in AngularJS (v1.3.15) using $resource and method 'HEAD'

angularjs,http-headers,ngresource

Thank you to Kevin for suggesting that I use an error handler. I should've thought to try that myself, but I didn't. Anyway, that lead me to the answer to my problem. To try and catch an error in $resource, it's suggested you use interceptors. I've never used them before...

I want to get the new ID when new record is created using web API and angular resource

angularjs,ngresource

You are most likely being passed back a json object from your api. So, newid is probably an json object. Try updating this line: $location.path('/project/' + newid); to $location.path('/project/' + newid.id); Also, make sure your api is really passing back the id in the response and check what the property...