Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8578969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:30:47+00:00 2026-06-11T20:30:47+00:00

I started developing in AngularJS. I’m confused as to whether this is a proper

  • 0

I started developing in AngularJS. I’m confused as to whether this is a proper design to pass data between my partial views.

Right now I have a loader page where I do some request.

function PeopleController($scope,$http,$location){
    $http.get('/location/-79.18925/43.77596').
    success(function(data){
      $scope.savePeopleResponse(data);
      $location.url('/test');
    });
}

Then in the view that gets loaded for /test

I am just calling

<div ng-controller="resultController">
    <div class="blueitem">{{getResultForPeople()|json}}</div>
</div>

[resultController]

    function resultController($scope){
      $scope.getResultForPeople = function(){
     return $scope.getPeopleResponse();
    }
}

and the savePeopleResponse and getResultForPeople are “cached” in the rootScope as such

app.run(function($rootScope) {
  var peopleResponse = {};
  $rootScope.savePeopleResponse = function(data) {
   peopleResponse = data;
   console.log(data);
  }

  $rootScope.getPeopleResponse = function(){
    return peopleResponse;
  }
});

Now as you can see, this will get very messy if this application grows larger and larger. What’s the best way to handle data so that it’s persisted across controllers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:30:49+00:00Added an answer on June 11, 2026 at 8:30 pm

    You can persist data across controllers by creating your own service as described nicely in this blog. You can also refer to this question.

    In your case you can move your savePeopleResponse and getPeopleResponse into a service and then inject the service into any controllers you would like to access it.

    angular.module('myApp', [])
        .factory('peopleService', function () {
            var peopleResponse = {};
    
            return {
                savePeopleResponse:function (data) {
                    peopleResponse = data;
                    console.log(data);
                },
                getPeopleResponse:function () {
                    return peopleResponse;
                }
            };
        });
    

    With your controller something like this:

    function resultController ($scope, peopleService) {
        $scope.getResultForPeople = peopleService.getPeopleResponse;
    }
    

    With this code example make sure you include ng-app="myApp"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started developing android apps and I am wondering about this right from
I recently started developing websites on wordpress. I have this problem with tinymce editor.
I have just started developing iPhone applications and I am very confused by how
I have just started developing iphone applications, but now i'm stuck with this problem,
I just started developing on Oracle. Is there a way to populate data in
This is just a curiosity question. I've started developing with AndEngine a 2d openGL
I started developing an Android application that record a video and I need to
I started developing an application in Silverlight that was dealing with downloading the HTML
I started developing an android app that have to interact with MMS attachements, in
I just started developing my brand new windows 8 application last week using mvvm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.