angular-http

AngularJs: How to cache $http properly?

谁说胖子不能爱 提交于 2019-12-11 23:35:55
问题 I've enabled cache in my $http request and now the callback for success only runs the first time. I'm wondering if this is expected or there's something I need to know about caching $http ? This is what I've been trying: $http.get('/foo/bar', { cache: true }) .success(function(data){ // does foo }) .error(function(){ // uh oh }); Let's say I've processed the data once, but there's also other commands that I'd like to run, every time. So, if it's true the data is cached or already available I

AngularJS $http.post

北慕城南 提交于 2019-12-11 13:15:54
问题 I am trying to do an $http.post and get the response, I tried in several ways but I can't get it working. The data I am sending (userData) is an json object. $http.post(url, userData) .success(function(data, status, headers, config) { console.log('post success'); console.log('data'); console.log(data); console.log('status'); console.log(status); console.log('headers'); console.log(headers); console.log('config'); console.log(config); }).error(function(data, status, headers, config) { console

Angular $http.jsonp() method works only once

早过忘川 提交于 2019-12-11 09:43:22
问题 Response is succeded (alert->done), but second and another hits will response 'error'. I've tried to add some config params with 'cache: false' but still works only first time. Should I clear some cache/history or sth? $scope.add2 = function() { var config = { //url : 'http://www.***.pl/index.php/json/getallusers', cache: false, //type : 'POST', crossdomain: true, //callback: 'JSON_CALLBACK', //data: d, contentType: "application/json", dataType: "jsonp", }; var r = Math.floor(Math.random() *

Is it possible to check condition before all http calls in Angular?

空扰寡人 提交于 2019-12-11 07:23:29
问题 Is it possible to check if: $rootScope.variable is TRUE Before all $http calls are called, or I should check for every individual call? Some of my calls are call through angular factory , and some are not. I thought there is maybe some way like httpInterceptor which would check before some call is ran. Any help would appreciated. 回答1: You can create an interceptor for this issue like this one: angular.module('myModule', []).config(function($httpProvider) { $httpProvider.interceptors.push

AngularJS 1 : $http always return status code -1 when request fails

浪子不回头ぞ 提交于 2019-12-11 07:17:01
问题 I would like to intercept 500 error and higher. I get inspired by: angular doc AngularJs - $http.get request, response with -1 status code and other similar questions this is the ServiceErrorInterceptor app.factory('ServerErrorInterceptor', [ '$q', function ($q) { return { 'requestError': function(rejection) { console.log( rejection ); return $q.reject(rejection); }, responseError: function (rejection) { console.log( rejection ); return $q.reject(rejection); } }; } ]); which always returns

How to appropriately handle error responses Angular 4.0.0

走远了吗. 提交于 2019-12-11 07:06:37
问题 I've got a problem with handling errors in Angular 4. Please advice me the proper approach. When server respond with error I'd like to redirect it to cache block and there I'd like to have a specific behaviour when status is 403. When I check the status in the first map() and throw an error from there - catch block is executed, but error is passing as a string with stack trace. It makes unpossible to recognize status in catch block again. How to do it right way? getLoggedInUser(): Observable

Angular 5 StaticInjectorError:[Http]

假装没事ソ 提交于 2019-12-11 06:56:42
问题 hello i am getting such an error what is the reason for this? StaticInjectorError[Http]: StaticInjectorError[Http]: NullInjectorError: No provider for Http! at NullInjector.get (core.js:923) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153)enter code here at StaticInjector.get (core.js:1024) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153) at StaticInjector.get (core.js:1024) at resolveNgModuleDep (core.js:10585) at NgModuleRef.get (core.js:11806) at resolveDep

Error loading @angular/common/http - angular 2

二次信任 提交于 2019-12-11 06:25:12
问题 I am trying to implement a service in Angular 2. Service: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import { BrowserModule } from '@angular/platform-browser'; @Injectable() export class DemoService { constructor(private http: HttpClient ) { } GetData(): Observable<String> { const baseUrl = 'http://localhost:54037/api/home'; // this part will come from config file in futer // const url = '

How can I cache some data in angular 4 service?

回眸只為那壹抹淺笑 提交于 2019-12-11 06:02:38
问题 I have a service that I call to pull some data from my rest service. I have an object that I set inside my service with the result from the rest call. The problem is that when I call the get function to return the object I always get undefined. I currently have the call to my service on the application root onInit function. Any help on how I could load this data and store on the object so next time I need to access it I do not need to make a remote call to my rest service? Here is my service

NULL http headers are passed to the server from Angular2 app

我的未来我决定 提交于 2019-12-11 04:46:51
问题 I have a REST api developed using SpringBoot and it contains the implementation for JWT for authentication and authorization. A FilterRegistrationBean is used for that. I have a class called JwtFilter which extends GenericFilterBean . In that I look for the content of the request headers in order to authorize the users. public class JwtFilter extends GenericFilterBean{ @Override public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws