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

  • SEARCH
  • Home
  • 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 8749631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:43:33+00:00 2026-06-13T12:43:33+00:00

While building an application using AngularJs I asked my self if the following is

  • 0

While building an application using AngularJs I asked my self if the following is good practice

I have “AppController” and every other controller is child of it. AppController has something like this.

$scope.layout = { sidebar: false, searchbar: true};

Now, child controllers should be able to change these values:

$rootScope.sidebar = true; 

In this case, my child module is totally dependent on root controller and if I want this child controller works inside some other application I have to make sure parent controller of that other app always have $scope.layout object. Is this good practice? Would it be better to build layout module used by both, parent and child controllers? Like code bellow:

angular.module("app.ui", [])
  .factory("Layout", [function(){
     var _sidebar = false;
     var searchbar = true;


     var sidebar = function(flag){
        if(flag !== undefined) _sidebar = flag;
        return _sidebar;
     }

     var searchbar = function(flag){
        if(flag !== undefined) _searchbar = flag;
        return _searchbar;
     }

return {
   sidebar : sidebar,
   searchbar : searchbar
}
}])
  • 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-13T12:43:34+00:00Added an answer on June 13, 2026 at 12:43 pm

    Whilst there may be other architectural approaches to what you want to do (e.g. look into the documentation on the scope property of directive declarations and its facilities for binding specific properties in the parent scope using @, = and &), generally Services are indeed a good option for sharing access to common data. You could simplify it a bit, if you don’t have extra logic that must happen when the values are updated:

    angular.module("app.ui", [])
    
    .service("Layout", function() {
      this.sidebar = false;
      this.searchbar = true;
    })
    

    If you inject this service into your controllers and add it to their scope, you can update it and listen for changes like this:

    .controller("AppCtl", function($scope, Layout) {
      $scope.Layout = Layout;
    
      // Method called by a search button, say
      $scope.search = function() {
        Layout.searchbar = true;
      }
    
      $scope.$watch("Layout.searchbar", function(newVal, oldVal) {
        // Do something in this scope if value has been changed from elsewhere
      });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem while building and running an iphone application.Im using xml parsing
Unlike this question: Linker Error while building application using Boost Asio in Visual Studio
I am building an application in Python and I have my whole package. While
While building several different projects in QtCreator, I have run across the following build
I seem to have hit a snag while building my project using Ant. The
I have application building using third party apis, j2me apis,application code distributed in various
I have tried to the comet chat application using streamhub (2.2.10 version), but while
I want to work on a supporting library while building an application while using
I found this bug error while building an application for iPhone using c#. This
I'm building an application using Visual Studio 2010 in which I have to use

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.