Using $http inside my own service - variable does not persist

Using $http inside my own service - variable does not persist

Content Index :

Using $http inside my own service - variable does not persist
Tag : angularjs , By : user170635
Date : November 27 2020, 11:01 PM

it helps some times Take these service and controller as an example and you should follow John Papa's style guide while writing the code.
(function() {
            'use strict';

                .factory('appAjaxSvc', appAjaxSvc);

            appAjaxSvc.$inject = ['$http', '$q'];

            /* @ngInject */
            function appAjaxSvc($http, $q) {

                return {
                    getData:function (path){

                      //Create a promise using promise library
                        var deferred = $q.defer();

                            method: 'GET', 
                            url: "file path to my server data"
                        success(function(data, status, headers,config){
                        error(function(data, status, headers,config){

                        return deferred.promise;
    (function() {

            .controller('appCtrl', appCtrl);

        appCtrl.$inject = ['$scope', '$stateParams', 'appAjaxSvc'];

        /* @ngInject */
        function appCtrl($scope, $stateParams, appAjaxSvc) {
            var vm = this;
            vm.title = 'appCtrl';



            function activate() {

                appAjaxSvc.getData().then(function(response) {
                    //do something
                }, function(error) {


No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Angular JS: Accessing a $scope.variable defined inside a $http.get block to use in another $http.get

Tag : javascript , By : Zinovate
Date : March 29 2020, 07:55 AM
wish of those help You are dealing with asynchronous code. By the time you are sending the second request, the first one isn't complete yet, so nextPageToken and prevPageToken aren't set yet. A simple solution would be to put the second request inside the success function of the first one:
$http.get('source').success(function(data) {
    $scope.nextPageToken = data.nextPageToken;
    $scope.prevPageToken = data.prevPageToken;
    $http.get('source&pageToken=' + $scope.nextPageToken).success(function(data) {
        $scope.picture = data.thumbnail.url;

How do I set a variable within an Angular JS service to the response data from an $http call within an AngularJS service

Tag : javascript , By : CM.
Date : March 29 2020, 07:55 AM
wish help you to fix your issue There is no need to cache the angular service, it's guaranteed to be a singleton.
If you mean to cache the response data, you will create a cache object in your service.
this.getActivities = function(x) {
    var promise = $http({
        method: 'GET',
        url: 'my url is here...'
    }).then(function(response) {
        setTemp(response.data); //meaning that setTemp somehow modifies it's argument
        return response.data;
    return promise;
.controller('someController', function (activityService) {
            .then(function (data) {

Invoke persist inside another persist event handler

Tag : scala , By : Nicholas Hunter
Date : March 29 2020, 07:55 AM
this will help Invoking persist from another persist will block the program. The correct way is to send a message to self. And then in the code to handle that message perform the persist.

Need to call angular http service from inside loop and wait for the value of the service to return before executing code

Tag : angularjs , By : Sigfrieg
Date : March 29 2020, 07:55 AM
this will help Have a scenario where we have a loop and inside the loop we need to call a http service to get information about each item in the loop. , Restructure your code so there is no loop, but recursive async calls:
var currentIndex = 0;
function processNext() {
    if (currentIndex >= $scope.searchResult.length) {

    var next = $scope.searchResult[currentIndex++];
    myService.getInfo(next).then(function (response) {
        var specialInfo = response.data;
        if (specialInfo.length > 0) {
            // something
        } else {
            // something else


var promises = $scope.searchResult.map(function (result) {
    return myService.getInfo(result);

$q.all(promises).then(function (responses) {
    responses.each(function (response) {
        // do stuff

Is it safe to use http inside service fabric cluster for service to service commiunication?

Tag : development , By : ChaseVoid
Date : March 29 2020, 07:55 AM
around this issue This is related to how do you set up your cluster with your network. Public facing services and internal services should be in a different NSG networks. You should control very strict communication between public and internal. If you can do that then http or any protocol between services is not a problem
Personally, i prefer http over remoting because there will be less dependency between services. Communication between services can be defined using Open API and therefore become vendor neutral.
Related Posts Related QUESTIONS :
  • Calling controller method using @Url.Action in angularjs
  • ui-router State Children and Resolvers
  • Select2 not working in angular
  • what can or cannot be done with a controller created in a module Vs controller created globally?
  • How to properly convert controller and service from AngularJS to using ng-resource
  • Have some generator can gener angular component api document?
  • AngularJs - communication between controller and directive
  • Angularjs - add ng-* attributes using directives
  • Define global variable with Typescript Angularjs in components
  • Angular UI-Router childs
  • Apache Alias forbidden
  • getSelectedRows in Angular UI grid
  • What is the use case of md-no-select-click in angularJs material tabs
  • Is it possible to resend image url received from server back to it as an image after processing
  • When is "onEnter" exactly executed
  • Jasmine how do I set the response of a spy
  • AngularJS date input not showing initial value inside directives in Firefox
  • What is scope of a variable inside ng-repeat block in angular js
  • Angular.Foreach in $firebaseObject
  • How to create a new instance of variables in AngularJs so that their values would be independent of the original one?
  • Is there a direct way to know to which view I am going in ionic?
  • How to use variable from a Controller in a Directive link function?
  • AngularJS - set validity of wrapped directives
  • AngularJS config causes error when minified
  • Why are my Angular, absolute path, URL's not compiling properly with Closure Compiler?
  • How to write test-case for Directive with in Directive using jasmine
  • How to pass variables from an array to ng-repeat
  • Launch an android app from Ionic app
  • Email Validation with AngularJS 1.2.0
  • How to pass data from login page to OAuth 2.0 and then get it back?
  • AngularJS routing not working properly in PhoneGap
  • AngularJS: Create new scope variable name using a variable value
  • Directive scope update does not update controller scope (AngularJs)
  • Angular UI Bootstrap4 Vertical Tabs
  • How to show/hide different data on clicking different links in AngularJS?
  • can i paste text input value on-keyup in angular?
  • ui-view do not bind to controler
  • ng-keyup doesn't execute the expression
  • Unit-test a angular controller function in a directive
  • AngularJS - always show two digits after comma
  • Angular View Showing Wrong Result
  • Angular not found until after it's needed?
  • learning angular, having issues with ng-options
  • Angularjs chat with strange polling
  • jQuery Sparkline in a cell in ng-grid using CellTemplate and Directive
  • AngularJS determine filter in controller
  • ADAL tokens not revoking on logout
  • How to deploy an app using ionic framework to Amazon? (elastic beanstalk prefered)
  • Conditional injection of a service in AngularJS
  • Filtering on object properties not working
  • Angularjs: Sorting not working in ui-grid with CellTemplate data
  • How to put serial number for rows in data table according to pagination
  • Play Application Couldn't be Started
  • Video capture to not show in my gallery on phone
  • Reject from 'response' into 'responseError'
  • Angular $injector vs inject
  • how to Avoid ng-repeat in <tr> for particular <td> - Angular Js?
  • Express route handling / req.body empty on some routes
  • AngularJS - Adding controller files triggering uncaught error
  • Using the browser to navigate back in an angularjs app with ui-router?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com