Service:
angular.module('frame-data-storage', []) .service('frameDataStorage', frameDataStorage); frameDataStorage.$inject = []; function frameDataStorage() { var _logo = '', _category = '', _pinfo = ''; return { setLogo: function (logo) { _logo = logo; }, setCat: function (category) { _category = category; }, setProviderInfo: function (pinfo) { _pinfo = 'dsdsdsaf443'; }, getLogo: function () { return _logo; }, getCat: function () { return _category; }, setProviderInfo: function () { return _pinfo; } } } A piece of controller from which data needs to be transferred
/*data to service*/ frameDataStorage.setLogo($scope.searchServices.icon); frameDataStorage.setCat($scope.categoryName); frameDataStorage.setProviderInfo($scope.providerInfo); /*end data to service*/ And the directive in which I want to pass
angular.module('navigation.frameNavBottom', []) .directive('frameNavBottom', ['frameDataStorage', function(frameDataStorage) { return { template: require('./templates/index.html'), link: function($scope, iElm, iAttrs, controller, $translate, frameDataStorage) { $scope.logo = frameDataStorage.getProviderInfo(); } } } ]); module.exports = 'navigation.frameNavBottom'; And another one
var app = angular.module('navigation.frameNavTop'); app.directive('frameNavTop', ['$window', frameNavTop]); function frameNavTop($window) { return { template: require('../templates/header.html'), controller: ['$rootScope', '$scope', '$state', '$document', 'Authentication', 'Bills', 'frameDataStorage', Ctrl], controllerAs: 'vm', }; function Ctrl($rootScope, $scope, $state, $document, Authentication, Bills, frameDataStorage) { $scope.state = $state; $scope.preLoader = false; $scope.sliderFormPreLoader = false; $scope._sliderFormActive = ''; $scope.isAuth = false; $scope.billsNum = 0; /*service frameDataStorage*/ $scope.logo = frameDataStorage.getLogo(); /*end service frameDataStorage*/ setTimeout(function(){ $("#payment-logo img").clone().appendTo("#service-logo-block"); }, 2500); $scope.goTop = function () { if($state.current.name == 'pages.main') { $document.scrollTopAnimated(0); } }; } } module.exports = app; So far I have decided with her the question in this way
setTimeout(function(){ /*service frameDataStorage*/ $scope.logo = frameDataStorage.getLogo(); console.log('logo',$scope.logo);//TODO: delete /*end service frameDataStorage*/ }, 2500); The problem is that data cannot be transferred to them. In the usual controller is different, everything works fine, the data is stored in the service. But in the directives he writes
TypeError: Cannot read property 'getProviderInfo' of undefined
.directive('frameNavBottom', ['frameDataStorage', function(frameDataStorage) {