Angular 4.3 – HttpClient set params

HttpParams is intended to be immutable. The set and append methods don’t modify the existing instance. Instead they return new instances, with the changes applied. let params = new HttpParams().set(‘aaa’, ‘A’); // now it has aaa params = params.set(‘bbb’, ‘B’); // now it has both This approach works well with method chaining: const params = … Read more

from jquery $.ajax to angular $http

The AngularJS way of calling $http would look like: $http({ url: “http://example.appspot.com/rest/app”, method: “POST”, data: {“foo”:”bar”} }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available $scope.data = response.data; }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. … Read more

Processing $http response in service

Here is a Plunk that does what you want: http://plnkr.co/edit/TTlbSv?p=preview The idea is that you work with promises directly and their “then” functions to manipulate and access the asynchronously returned responses. app.factory(‘myService’, function($http) { var myService = { async: function() { // $http returns a promise, which has a then function, which also returns a … Read more

AngularJs $http.post() does not send data

I had the same problem using asp.net MVC and found the solution here There is much confusion among newcomers to AngularJS as to why the $http service shorthand functions ($http.post(), etc.) don’t appear to be swappable with the jQuery equivalents (jQuery.post(), etc.) The difference is in how jQuery and AngularJS serialize and transmit the data. … Read more

How can I post data as form data instead of a request payload?

The following line needs to be added to the $http object that is passed: headers: {‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’} And the data passed should be converted to a URL-encoded string: > $.param({fkey: “key”}) ‘fkey=key’ So you have something like: $http({ method: ‘POST’, url: url, data: $.param({fkey: “key”}), headers: {‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’} }) From: https://groups.google.com/forum/#!msg/angular/5nAedJ1LyO0/4Vj_72EZcDsJ UPDATE To … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)