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; }); } ...
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...
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...
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...
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...
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...
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...
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...
Just provide a function that returns your value (see documentation): $resource('/:localeId/...', { localeId: function () { return $locale.id; }, // ... }) ...
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 =...
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...
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...
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....
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...
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:...
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 }); ...
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...
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...
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...
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...
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); }); ...
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...
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); },...
You should call: ProductData.delete(...) in the $scope.deleteProduct function
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 =...
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...
javascript,angularjs,ngresource
Change tileServiceCall.get(..) to tileServiceCall.query(...).
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...
angularjs,angular-resource,ngresource
I don't see a reason to fetch it again, I would just reuse the object.
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...
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...
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...
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> ...
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,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
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....
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....
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}); ...
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. ...
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...
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!...
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...
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...
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);.
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...
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) { .... ...
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'); ...
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 = [];...
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.
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}...
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...
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...
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...
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...