ngresource

AngularJS $state.go executes before previous statement execution completes

这一生的挚爱 提交于 2019-12-24 13:05:01
问题 I am using AngularJS, ui-router and $resource for RESTful webservices. A button in html view is clicked that calls below function i.e. $scope.login(). Consequently a REST service (through $resource) is called and returns a user in case user/pass are correct, $scope.login = function() { myfactory.get({ email: $scope.user.email, password: $scope.user.password },function(user) { accessmgr.grantAccess(user); //Line of interest - loi1 $state.go('app.dashboard-v1'); //Line of interest2 - loi2 },

ng-grid doesn't populate with angular $resource

百般思念 提交于 2019-12-24 12:25:43
问题 I'm trying to populate an ng-grid, using and ngResource $resource call, but it seems that the ajax call is always too late, after the ng-grid has already been rendered. The grid renders the headers but is not populated with data. Here's a snippet of the code and a jsfiddle angular.module('api', [ 'ngResource' ]).factory("SERVICE", function($resource) { return $resource('/api/...', {}, { query : { method : 'GET', isArray : true, transformResponse : function(data, headers) { var responsedata =

AngularJS - $resource + ng-repeat issue

岁酱吖の 提交于 2019-12-24 11:39:09
问题 In my html file I have the following table: <div ng-controller="InstructorCtrl"> <table class="table table-bordered"> <thead> <tr> <th>Title</th> <th>Name</th> </tr> </thead> <tbody> <tr ng-repeat="instructor in instructors"> <td>{{instructor.title}}</td> <td>{{instructor.name}}</td> </tr> </tbody> </table> </div> Here's how controller looks: angular.module('angularFrontendApp') .controller('InstructorCtrl', function ($scope, Instructor) { $scope.instructors = []; $scope.instructors =

What's the parameter for ngResource save() method's callback

淺唱寂寞╮ 提交于 2019-12-24 08:19:43
问题 I'm refactoring my angular code from using $http to ngResource. I used to have code like this in my service: svc.login = function(username, password) { return $http.post(apiEndpoint + 'authenticate', { username: username, password: password }) .then(function(val) { console.log("user token:", val.data); svc.token = val.data; }); }; The user token printed will be a jwt token. Now I try to refactor the code to something like this: svc.login = function(username, password) { svc.authenticateApi()

handle error callback on save() method $ngResource

守給你的承諾、 提交于 2019-12-23 20:57:20
问题 I need to handle error callback of an update operation, for this i'm using method save() like this: $scope.save = function (params) { MigParams.save(params); }; Migparams service look like this: angular.module('monitor'). factory('MigParams', function ($resource) { return $resource('/restful/migparams'); }); This code works great but i need to know if an error occurs in database. I have searched in google but i didn't find this particular case. Is there a way of get this?. Thanks in advance

How to save rows in a grid that I made a change to

为君一笑 提交于 2019-12-21 04:04:20
问题 I used ng-resource to get data from my server and then place the data into a table grid like this: <div ng-form name="grid"> <button type="submit" data-ng-disabled="grid.$pristine">Save</button> <div class="no-margin"> <table width="100%" cellspacing="0" class="form table"> <thead class="table-header"> <tr> <th>ID</th> <th>Title</th> </tr> </thead> <tbody class="grid"> <tr data-ng-repeat="row in grid.data"> <td>{{ row.contentId }}</td> <td><input type="text" ng-model="row.title" /></td> </tr>

post data - ngResource AngularJS

余生颓废 提交于 2019-12-20 04:19:03
问题 Hello ! I develop a RESTful webapp with AngularJS, I use the ngResource module to send http requests. The webservice is developped with FuelPHP. I'm having a problem to creating a resource with the $save method of ngResource . My web service doesn't receive post data. When I check the http request with Firebug, I can see the post data. I don't understand why the post data are not received by the webservice. So if you have an idea, it would be cool to help me. Sorry for my bad level in English

How can I use my JSON without triggering a new API request everytime I want to use my data?

♀尐吖头ヾ 提交于 2019-12-18 09:45:18
问题 I'm wanting to to have my app limit its requests to the server without saving the data. Is there a way I can do this without making a request to the server every time my http request is invoked? What are some of the different methods this can be done and best practices/trade offs for each? 回答1: That would depend on you needs. One approach would be to store the results in a request in a factory and retrieve those. app.factory('DataService', function($http) { var values; var requestValues =

Guidance on unit testing REST call in controller returning a promise

耗尽温柔 提交于 2019-12-14 02:39:00
问题 I'm able test - $scope.dvModel = DienstverlenerDetailService.query(); - accordingly. I cant figure out how to test the commented-out lines. Sure could you use some guidance on that. angular.module('dvb.controllers').controller('ServiceFacilitatorEditController', ['$scope', 'DienstverlenerDetailService', function( $scope, DienstverlenerDetailService) { 'use strict'; $scope.dvModel = DienstverlenerDetailService.query(); /*DienstverlenerDetailService.query().$promise.then( function(response) {

Testing a controller that execute a service with $resource response

痞子三分冷 提交于 2019-12-13 05:25:30
问题 I have a controller that use a service, resolve a promise and then set a variable. I want to test if the variable has been set, How I do this? Service.js angular .module('myModule') .service('MyService',['$resource',function($resource){ var r = $resource('/users/:id',{id:'@id'}); this.post = function(_user){ return (new r(_user)).$save() } }]) Controller angular .module('myModule') .controller('myCtrl', ['MyService',function(MyService){ var vm = this; vm.value = 0; vm.post = function(_user){