angular-resource

Getting ActionController::RoutingError (No route matches [OPTIONS] “/users” when trying to POST data to RAils server with AngularJS

橙三吉。 提交于 2021-02-16 13:06:24
问题 Having issue when trying to POST data to Rails server from my AngularJS side. The server error: ActionController::RoutingError (No route matches [OPTIONS] "/users"): actionpack (4.1.9) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' actionpack (4.1.9) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' railties (4.1.9) lib/rails/rack/logger.rb:38:in `call_app' railties (4.1.9) lib/rails/rack/logger.rb:20:in `block in call' activesupport (4.1.9) lib/active_support

AngularJS CSV File Download from API

我的梦境 提交于 2021-02-07 21:01:30
问题 I have an admin control panel where admin users can set a few options and then click a button to run a report. The report should return a CSV file download prompt to the user. I am using ui-router and $resource services. The response headers/mime type are set correctly, but the CSV file is returned as text (no file download initiated) by the $resource handler. I tried creating the download link directly, by forming a querystring from the $scope , but unfortunately my API's authentication

AngularJS CSV File Download from API

[亡魂溺海] 提交于 2021-02-07 20:52:52
问题 I have an admin control panel where admin users can set a few options and then click a button to run a report. The report should return a CSV file download prompt to the user. I am using ui-router and $resource services. The response headers/mime type are set correctly, but the CSV file is returned as text (no file download initiated) by the $resource handler. I tried creating the download link directly, by forming a querystring from the $scope , but unfortunately my API's authentication

Set controller variable by calling c# webservice from angular with the use of $resource

你说的曾经没有我的故事 提交于 2020-01-16 01:13:07
问题 I have a problem with using the JSON data which is comming from a service. The backend is written in c# and the frontend in AngularJS. I am not able to use the object as I want in the Angular controller. So, here is my api restful service in C# [Route("v1/environment")] public IHttpActionResult GetEnvironment() { var env = new Environment(WebConfigurationManager.AppSettings["Env"]); return this.Ok(env); } Then, here is my angular service: module.factory('Environment', [ '$resource', function

AngularJS $promise then() data undefined

佐手、 提交于 2020-01-11 02:27:23
问题 I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The following is my controller code: angular.module('testSiteApp').controller('TestController', function ($scope, Tests) { $scope.test = Tests.get({id: 1}); $scope.test.$promise.then(function(data) { $scope.tasks = data.tasks; console.log($scope.tasks); }); console.log($scope.tasks); }); The results inside the then() function:

AngularJS $promise then() data undefined

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 02:27:06
问题 I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The following is my controller code: angular.module('testSiteApp').controller('TestController', function ($scope, Tests) { $scope.test = Tests.get({id: 1}); $scope.test.$promise.then(function(data) { $scope.tasks = data.tasks; console.log($scope.tasks); }); console.log($scope.tasks); }); The results inside the then() function:

AngularJS check if promise is empty or not

淺唱寂寞╮ 提交于 2020-01-07 09:35:11
问题 Hi I have this code for the purpose of checking if there are users in the database, if it finds shows a list of users on a view, otherwise shows a view with form of user creation, but didn't work the check expression what I'm doing wrong users = Users.query(); users.$promise.then( function (data) { if (!data) { $location.url('/NewUser') } else { $location.url('/UsersList') } }); 回答1: It is probably returning an empty array in case nothing is found. Try checking the data length. if (data

AngularJS check if promise is empty or not

僤鯓⒐⒋嵵緔 提交于 2020-01-07 09:35:06
问题 Hi I have this code for the purpose of checking if there are users in the database, if it finds shows a list of users on a view, otherwise shows a view with form of user creation, but didn't work the check expression what I'm doing wrong users = Users.query(); users.$promise.then( function (data) { if (!data) { $location.url('/NewUser') } else { $location.url('/UsersList') } }); 回答1: It is probably returning an empty array in case nothing is found. Try checking the data length. if (data

Reject Angularjs resource promises

…衆ロ難τιáo~ 提交于 2020-01-03 22:11:51
问题 So I'm working on a Angularjs based mobile app. When a user taps on each of the tabs along the bottom a new route is called which is loading the partial and controller. In my controllers I often then request data from the server via Angularjs $resource such as $rootScope.getPage = pageApi.query(); // GET $rootScope.getPage = $rootScope.getPage.$promise.then(function(data) { //Do stuff with the returned data }); I'm using root scope here because I have a spinning loader located outside of the

How do I remove the default headers just for specific XHR requests in AngularJS?

折月煮酒 提交于 2020-01-02 01:07:33
问题 99% of my ajax calls need a specific "X-API-TOKEN" to authenticate and communicate with my Rails REST API. But I'm also making a call to one thrid party API and I keep getting an error saying "Request header field X-API-TOKEN is not allowed by Access-Control-Allow-Headers." Everything works fine if I delte the header right before the call, and a work around would be to delete and then re-add after the call, but is there an easier way than this: apiToken = $http.defaults.headers.common["X-API