angular-http

How to Show spinner for every HTTP requests in angular 5?

狂风中的少年 提交于 2019-12-13 13:06:15
问题 i am new to angular 5 . How to code a common function to show spinner for every HTTP request in angular 5.Please help me to implement this. 回答1: You can use Angular HttpInterceptor to show a spinner for all your requests, Here's a good medium article on how to implement an http interceptor Also, you will have to create a spinner service/module and inject it in your http interceptor. Finally, in your intercept method you can use the finally rxJs method to stop your spinner. Here's a simple

Update a complex object on Backand using $http PUT

南笙酒味 提交于 2019-12-13 02:21:35
问题 I am using Backand to provide the database and REST api for my Angular app. I am working on a capability for users to make edits to a complex object, which should then be updated on the database. Straightforward enough... The object looks a bit like this: obj = { id: 1, // assigned by the db name: "My List", tasks: [ { id: 1, desc: "Task 1" }, { id: 2, desc: "Task 2" }, ... ] } For the update ($http PUT) call, I would like to use params: { deep: true } as a shortcut to minimise code and $http

AngularJS version 1.6 change from `.success` method to `.then` method

ぐ巨炮叔叔 提交于 2019-12-12 14:22:49
问题 actually am following a spring tutorial .. coming to Angularjs he is using .succes var app=angular.module("MyApp",[]); .controller("MyController",function($scope,$http){ $scope.pageProduits=null; $http.get("http://localhost:8080/chercherProduits?mc") .success(function(data){ $scope.pageProduits=data; }) .error(function(err){ console.log(err); }); }); now my problem is that success is not working and after searshing i descovered that The .success and .error methods are deprecated and have been

AngularJS - Return in success $http.post

纵然是瞬间 提交于 2019-12-12 14:09:03
问题 I use AngularJs and I need to return a data after a $http.post connection. This is the code: app.controller('PrincipalController',['$http', '$scope', function($http,$scope){ $scope.myData = 0; $http.post("server/checklogin.php", {id: "id",email: "email",password: "password"} ) .success(function(data){ console.log($scope.myData) //0 $scope.myData = data; console.log($scope.myData); // 1 } OLD: How can I pass the data into myData? - Thanks for your answers and sorry if I haven't explained well.

Spring Controller 400 (Bad Request)

一世执手 提交于 2019-12-12 04:55:50
问题 I am getting bad request issue from spring controller. (Reason : The request sent by the client was syntactically incorrect.) Below is my rest call : Requested payload: categoty: "Game" itemDescription: "adas" itemDiscount: 1 itemName: "asdas" itemPrice: 1 itemQuantity: 1 Rest Method @RequestMapping(value="/addItem", method = RequestMethod.POST,headers="Accept=application/json") public @ResponseBody String createItem(@RequestBody Item item) { ItemDAO itemDAO=new ItemDAO(item); try{ itemDAO

Upload a file from a local directory using Angular 1.6.2

血红的双手。 提交于 2019-12-12 03:58:12
问题 I am building an application using angular 1.6.2. I have an image upload button in one of my partials. I'm developing the site and running the server on my local laptop. All I need to do is upload these images into an images folder in my project locally. I don't need to do anything fancy. Am I able to get away with only using HTML5 or do I have to use JavaScript or jQuery? If I do need js or jq, what would the code look like? Here is my partial: <div class="form-group"> <label>Please Upload

Assigning variable from a factory to a control doesn't work

一曲冷凌霜 提交于 2019-12-12 03:46:00
问题 My html is this: <body ng-controller="MainCtrl as ctrl" class="bodyContainer"> <div ng-repeat="stuff in ctrl.stuffies"> here </div> This is my controller: angular.module("AuthenticationApp", ["BaseApp"]) .controller("MainCtrl", ["$http", "$window", "BaseService", function($http, $window, BaseService) { var self = this; BaseService.fetch.stuffs(function() { self.stuffies = BaseService.stuffies; console.log(self.stuffies); self.cerrorMessages = BaseService.cerrorMessages; }); }]); And this is

AngularJS directive with $http requests (inprog error)

落爺英雄遲暮 提交于 2019-12-12 02:55:32
问题 I've searched and tried many things for this, and I think maybe Im just doing it wrong. I have a single page app that has very similar DOM pieces, differentiated only by the data that is fed in to them from a service. Each DOM piece has a different web service. My HTML looks something like this <div section="foo"> <ul> <li ng-repeat="item in collection">{{item.name}}</li> </ul> </div> <div section="bar"> <ul> <li ng-repeat="item in collection">{{item.cost}}</li> </ul> </div> The differences

How to correctly override `errResponse` which is passed to the `catch(function(errResponse){` function?

淺唱寂寞╮ 提交于 2019-12-12 02:38:47
问题 This is my controller: angular.module("AuthenticationApp", ["BaseApp"]) .controller("MainCtrl", ["$http", "$window", "BaseService", function($http, $window, BaseService) { var self = this; self.add = function() { BaseService.add.user(self.user) .catch(function(errorResponse) { self.cerrorMessages = errorResponse.data; }); }; This is my BaseApp / factory: angular.module("BaseApp", []) .config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.xsrfCookieName = 'csrftoken';

How to use $q's constructor syntax with Angular $http's config.timeout?

不羁的心 提交于 2019-12-12 02:17:01
问题 Since Promise is now officially spec-ed and all, how do I convert the $q.defer() promise creation in the following snippet to use the $q(function (resolve, reject) {}) constructor syntax instead? // Cancel any ongoing $http request so that only the most recent $http // callback gets invoked var canceller; function getThing(id) { if (canceller) canceller.resolve(); canceller = $q.defer(); return $http.get('/api/things/' + id, { timeout: canceller.promise }); } (Fyi from $http docs: timeout is