angular-http

$http get parameters does not work

谁说我不能喝 提交于 2019-11-26 19:05:00
问题 Does anyone know why this does not work? $http .get('accept.php', { source: link, category_id: category }) .success(function (data, status) { $scope.info_show = data }); and this does work: $http .get('accept.php?source=' + link + '&category_id=' + category) .success(function (data, status) { $scope.info_show = data }); 回答1: The 2nd parameter in the get call is a config object. You want something like this: $http .get('accept.php', { params: { source: link, category_id: category } }) .success

How to make an http call every 2 minutes with RXJS?

↘锁芯ラ 提交于 2019-11-26 16:53:45
问题 I have a service that will make a call to my rest service every 2 minutes. On my service I have the following function getNotifications(token: string) { const body = 'xxxxxxxxx=' + token; return this.http.post('/rest/ssss/ddddddd/notificationcount', body, this.options) .map((res) => res.json()); } On my component I call my service function to call the API. this.notificationService.getNotifications(this.token).subscribe((data) => { console.log(data); }); I want to make this call every 2

from jquery $.ajax to angular $http

北慕城南 提交于 2019-11-26 14:03:28
I have this piece of jQuery code that works fine cross origin: jQuery.ajax({ url: "http://example.appspot.com/rest/app", type: "POST", data: JSON.stringify({"foo":"bar"}), dataType: "json", contentType: "application/json; charset=utf-8", success: function (response) { console.log("success"); }, error: function (response) { console.log("failed"); } }); Now I'm tring to convert this to Angular.js code without any success: $http({ url: "http://example.appspot.com/rest/app", dataType: "json", method: "POST", data: JSON.stringify({"foo":"bar"}), headers: { "Content-Type": "application/json; charset

AngularJs ReferenceError: $http is not defined

情到浓时终转凉″ 提交于 2019-11-26 12:38:07
问题 I have the following Angular function: $scope.updateStatus = function(user) { $http({ url: user.update_path, method: \"POST\", data: {user_id: user.id, draft: true} }); }; But whenever this function is called, I am getting ReferenceError: $http is not defined in my console. Can someone help me understanding what I am doing wrong here? 回答1: Probably you haven't injected $http service to your controller. There are several ways of doing that. Please read this reference about DI. Then it gets

How to use $http promise response outside success handler

天大地大妈咪最大 提交于 2019-11-26 10:57:47
$scope.tempObject = {}; $http({ method: 'GET', url: '/myRestUrl' }).then(function successCallback(response) { $scope.tempObject = response console.log("Temp Object in successCallback ", $scope.tempObject); }, function errorCallback(response) { }); console.log("Temp Object outside $http ", $scope.tempObject); I am getting response in successCallback but not getting $scope.tempObject outside $http . its showing undefined . How to access response or $scope.tempObject after $http But if I want to use $scope.tempObject after callback so how can I use it. ? You need to chain from the httpPromise.

Angularjs autocomplete from $http

微笑、不失礼 提交于 2019-11-26 10:09:11
问题 I\'m trying to write an autocomplete directive that fetches data from the server using an $http request (without using any external plugins or scripts) . Currently it works only with static data. Now, I know that I need to insert my $http request into the source: of the directive, but I can\'t find any good documentation on the subject. http request $http.post($scope.url, { \"command\": \"list category() names\"}). success(function(data, status) { $scope.status = status; $scope.names = data;

How to read response headers in angularjs?

夙愿已清 提交于 2019-11-26 07:34:54
问题 My server returns this kind of header: Content-Range:0-10/0 : I tried to read this header in angular with no luck: var promise = $http.get(url, { params: query }).then(function(response) { console.log(response.headers()); return response.data; }); which just prints Object {content-type: \"application/json; charset=utf-8\"} Any ideas how to access the content range header? 回答1: Use the headers variable in success and error callbacks From documentation. $http.get('/someUrl'). success(function

Angular 4.3 - HttpClient set params

自作多情 提交于 2019-11-26 05:57:55
问题 let httpParams = new HttpParams().set(\'aaa\', \'111\'); httpParams.set(\'bbb\', \'222\'); Why this doesn\'t work? It only set the \'aaa\' and NOT the \'bbb\' Also, I have an object { aaa: 111, bbb: 222 } How can I set all the values without looping? UPDATE (this seems to work, but how can avoid the loop?) let httpParams = new HttpParams(); Object.keys(data).forEach(function (key) { httpParams = httpParams.append(key, data[key]); }); 回答1: Before 5.0.0-beta.6 let httpParams = new HttpParams();

from jquery $.ajax to angular $http

六月ゝ 毕业季﹏ 提交于 2019-11-26 03:47:32
问题 I have this piece of jQuery code that works fine cross origin: jQuery.ajax({ url: \"http://example.appspot.com/rest/app\", type: \"POST\", data: JSON.stringify({\"foo\":\"bar\"}), dataType: \"json\", contentType: \"application/json; charset=utf-8\", success: function (response) { console.log(\"success\"); }, error: function (response) { console.log(\"failed\"); } }); Now I\'m tring to convert this to Angular.js code without any success: $http({ url: \"http://example.appspot.com/rest/app\",

How to use $http promise response outside success handler

大兔子大兔子 提交于 2019-11-26 03:28:46
问题 $scope.tempObject = {}; $http({ method: \'GET\', url: \'/myRestUrl\' }).then(function successCallback(response) { $scope.tempObject = response console.log(\"Temp Object in successCallback \", $scope.tempObject); }, function errorCallback(response) { }); console.log(\"Temp Object outside $http \", $scope.tempObject); I am getting response in successCallback but not getting $scope.tempObject outside $http . its showing undefined . How to access response or $scope.tempObject after $http 回答1: But