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
}
}])