I want data received by the service to be transmitted to the controller but the controller does not receive the data.
Service:
angular.module('dataService', [])
.constant('productCategoryUrl', ' /api/product/categories')
.service('dataService', function ($rootScope, $http, $filter, $rootScope, productCategoryUrl) {
var currentData = {};
var productCategories = [];
return {
setCurrentCategory: function (category, type) {
$rootScope.$broadcast('set-category', currentData);
},
}
})
Controller:
angular.module('jordans')
.controller('productCategoryCtrl', function ($scope, $rootScope, dataService) {
$scope.productCategories = [];
$rootScope.$on('set-category', function (e, args) {
$scope.currentData.category = args.category;
$scope.currentData.type = args.type;
console.log('*******productcategory.currentdata = '
+ JSON.stringify($scope.currentData))
});
}