restangular

Having Restangular's .remove send data in body vs URI

喜欢而已 提交于 2019-12-10 18:08:23
问题 I am in the process of converting my Angular REST calls to utilize Restangular. During this conversion I am simply moving the calls to use Restangular.one('controller').remove(object); This is calling the correct URI and method DELETE but is sending the object in the URI instead of the body. Is there an easy way to tell Restangular to send the object in the body? For POST/PUT I have utilized customPOST and customPUT which send the data in the body. Any pointers would be much appreciated. 回答1:

AngularJS change URL in module.config

五迷三道 提交于 2019-12-09 19:19:30
问题 I use Restangular in my angularjs App & use setErrorInterceptor to handle response error in one place. I want to redirect user to login page if an error occured. I know that the only providers & constants are injectable in configuration phase. var app = angular.module('ourstandApp', ['ngRoute', 'restangular', 'ui.bootstrap', 'ngCookies', 'angularFileUpload']); // Global configuration app.config(function (RestangularProvider, baseRequestConfig, $routeProvider, urlsProvider) { var

Setting headers and http params for a single request in restangular

岁酱吖の 提交于 2019-12-08 16:43:53
问题 I am trying to use restangular for file upload post request , I want to achieve the same functionality as below in restangular. However, I was unsure how to set content type and transformRequest for just this particular request. If I understand correctly, setDefaultHeader sets it for all subsequent requests. Is there some other way? myApp.service('$fileUpload', ['$http', function ($http) { this.uploadFileToUrl = function(file, uploadUrl){ var filedata = new FormData(); filedata.append('file',

Simple restangular example broken with AngularJS 1.2

感情迁移 提交于 2019-12-08 08:37:20
问题 I'm doing a basic Restangular example and it works on AngularJS 1.1 , however on 1.2 , the REST request is sent, data is received, but the table is not displayed properly. I read through some threads here about upgrading from 1.1 to 1.2 but I don't see the issue as the example is very simple and does not explicitly use ngRoute , isolated scopes or custom directives. HTML <!DOCTYPE html> <html ng-app="countries"> <head> <meta charset="utf-8" /> <title>REST Country Example</title> <link rel=

AngularJS (Restangular CRUD , Simplify / DRY Controllers?)

こ雲淡風輕ζ 提交于 2019-12-08 05:00:55
问题 Below a small example of what I want to simplify. I have the same structure set up for a few other models, and was wondering if I could prevent typing out the same functionality but with just different messages/model. Is it possible to reuse a controller & pass parameters? (In this case, the name of the model + the messages that need to be shown...). Ideally, I just want the basic CRUD controller to be reused, but allow custom methods, just in case. angular.module('employees.controllers', [

Custom Restangular GET method

本秂侑毒 提交于 2019-12-08 04:50:14
问题 I'm making a GET request to my web api, the url goes like /users/exist/:username I've created the custom method that works: RestangularProvider.addElementTransformer('users', true, function(user) { user.addRestangularMethod('exist', 'get', 'exist'); return user; }); But I don't know how to add the :username in the url. Is it even possible? 来源: https://stackoverflow.com/questions/25426020/custom-restangular-get-method

How can check offline and online in angular

◇◆丶佛笑我妖孽 提交于 2019-12-07 17:07:38
问题 I have been getting an error from the service call when browse is in offline mode. How can check off-line mode and want to block my service call when the browser is the offline mode? 回答1: I suggest you to use Offline.js they have templates and other stuff to work with . you can check out their documentation and see how it works . it gets you the current state of the connection by returning the "up" or "down" result , or you can bind and event to it and use it across you'r application . this

Injecting auth headers with angularjs and restangular

混江龙づ霸主 提交于 2019-12-07 06:40:21
问题 I am creating a RESTFUL webservice that is called from an angularjs app which uses the restangular service. The REST service requires that an auth token is sent with each request. How can I get this sent with each request using restangular? Looking at the documentation I can see there is a setRequestInterceptor method that I can set in the config which looks like I might be able to use: RestangularProvider.setFullRequestInterceptor(function(element, operation, route, url, headers, params) {

CORS in Node.js and AngularJS

落花浮王杯 提交于 2019-12-07 06:09:18
问题 I have a CORS problem with my app. My stack is Node.js with Express 4 and AngularJS using Restangular I already have tried a few things (for example) but I keep getting: XMLHttpRequest cannot load http://localhost:8080/api/users. Request header field Content-Type is not allowed by Access-Control-Allow-Headers. In the server side I have this headers: app.all('/*', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested

Restangular response and ng-repeat

倖福魔咒の 提交于 2019-12-07 05:15:45
问题 I have recently started to learn angularjs using restangular to talk to my restfull API (sails). The problem I have stumbled upon is that the ng-repeat does not update after I change the list in the scope. Controller: app.controller('UsersCtrl', ['UsersSvc', '$scope', function(UsersSvc, s) { UsersSvc.getList().then(function (new_users) { s.users = new_users; }) s.destroy = function (user) { user.remove().then(function () { s.users = _.without(s.users, user); }); } }]); Service: app.factory(