Angularjs autocomplete from $http

I made an autocomplete directive and uploaded it to GitHub. It should also be able to handle data from an HTTP-Request. Here’s the demo: http://justgoscha.github.io/allmighty-autocomplete/ And here the documentation and repository: https://github.com/JustGoscha/allmighty-autocomplete So basically you have to return a promise when you want to get data from an HTTP request, that gets resolved when the … Read more

No methods in http response object

The server just returns data formed with properties from the defined object. It doesn’t actually create an instance of the object. Try something like this: this.lab = Object.assign(new Lab(), this.retrievedLab) Where this.retrievedLab is the data returned from the server. This should create the object and then copy any of the retrieved properties into it.

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

Since you are already using Observables, simply make full use of it 🙂 Obersvable.interval() is your good friend here: In your component, do this: Observable .interval(2*60*1000) .timeInterval() .mergeMap(() => this.notificationService.getNotifications(this.token)) .subscribe(data => { console.log(data); }); Explanation: .interval() creates an observable that emits an event every 2 minutes. .timeInterval() convert an Observable that emits items into … Read more

How to read response headers in angularjs?

Use the headers variable in success and error callbacks From documentation. $http.get(‘/someUrl’). success(function(data, status, headers, config) { // this callback will be called asynchronously // when the response is available }) .error(function(data, status, headers, config) { // called asynchronously if an error occurs // or server returns response with an error status. }); If you … Read more

Angular 4.3 – HttpClient set params

Before 5.0.0-beta.6 let httpParams = new HttpParams(); Object.keys(data).forEach(function (key) { httpParams = httpParams.append(key, data[key]); }); Since 5.0.0-beta.6 Since 5.0.0-beta.6 (2017-09-03) they added new feature (accept object map for HttpClient headers & params) Going forward the object can be passed directly instead of HttpParams. getCountries(data: any) { // We don’t need any more these lines // … 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

How to use $http promise response outside success handler

But if I want to use $scope.tempObject after callback so how can I use it. ? You need to chain from the httpPromise. Save the httpPromise and return the value to the onFullfilled handler function. //save httpPromise for chaining var httpPromise = $http({ method: ‘GET’, url: ‘/myRestUrl’ }).then(function onFulfilledHandler(response) { $scope.tempObject = response console.log(“Temp Object … Read more

How to POST binary files with AngularJS (with upload DEMO)

RECOMMENDED: POST Binary Files Directly Posting binary files with multi-part/form-data is inefficient as the base64 encoding adds an extra 33% overhead. If the server API accepts POSTs with binary data, post the file directly: function upload(url, file) { if (file.constructor.name != “File”) { throw new Error(“Not a file”); } var config = { headers: {‘Content-Type’: … Read more