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 ?
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';
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.