I am currently troubleshooting a software application developed by someone else. The code uses Angular 1.5.9, which is not my area of expertise, and I've hit a roadblock in finding solutions to my queries.
I need to invoke a $scope function from a separate controller, located in a different JavaScript file.
When trying to use the broadcast statement below, I encounter an error message: "TypeError: Cannot read property '$broadcast' of null". I'm unsure about the cause of this error.
Here is the code:
CONTROLLER 1:
app.controller('FilterController', function ($scope, $filter,
$uibModalInstance, errorService, dataService, values) {
$scope.sortByColumn = function () {
var data = { 'editorID': $scope.editorID(), 'filter':
dataService.data.objFilterColumns };
dataService.getData('UpdateFilter', data).then(function (response) {
$uibModalInstance.dismiss('cancel');
//I WANT TO CALL THE SCOPE 'reloadData' FUNCTION HERE
$scope.$emit('reloadData', data);
//this broadcast statement was already there but it throws error
$scope.$parent.$broadcast('sortbyColumn', $scope.userFilters, $scope.column.strColumnName, $scope.orderDir, dataService.data.objFilterColumns);
});
});
CONTROLLER 2:
app.controller("myCtrl", [
"$scope",
"$http",
"$uibModal",
"$log",
"$location",
"$window",
"dataService",
"errorService",
"lookupService"
, function ($scope, $http, $uibModal, $log, $location, $window, dataService, errorService, lookupService) {
$scope.loadPage = function (data, message, removeFilter, byColumn,
orderDir) {
//I want to call this function from the other controller
}
$scope.$on("reloadData", function () {
$scope.loadPage();
});
$scope.$on("sortbyColumn", function (event, filters, column, orderDir, filter) {
//some code
});
}]);
Appreciate your assistance with this matter.