zelocalhost
zelocalhost

Reputation: 1183

$rootScope and $scope, shared object

In an angularjs app, i define in a controller $scope.pimp.init, and in other controller $scope.pimp.panels, so, what i must put to init pimp : $scope.pimp= {}; or $rootScope.pimp = {}; , in the angular run starting ?

Upvotes: 0

Views: 45

Answers (1)

OJ Raqueño
OJ Raqueño

Reputation: 4561

Here is an example of how it can be implemented using services.

Service:

myApp.service('pimpService', [function () {
    return {
        pimp: {
            init: null,
            panels: null
        }
    };
}]);

Controllers:

myApp.controller('ctrl1', ['$scope', 'pimpService', function ($scope, pimpService) {
    pimpService.pimp.init = 'foo';
};

myApp.controller('ctrl2', ['$scope', 'pimpService', function ($scope, pimpService) {
    pimpService.pimp.panels = 'bar';
};

Upvotes: 2

Related Questions