我正在调试别人的软件。它使用 Angular 1.5.9,我对它不是很熟悉,也无法找到我问题的答案。
我想从单独的 js 文件中的另一个控制器调用存在于单独控制器中的 $scope 函数。
下面的广播语句引发错误,我不确定为什么?“类型错误:无法读取 null 的属性‘$broadcast’”
这是代码:
控制器 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);
});
});
控制器 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
});
}]);
谢谢你的帮助
www说
慕姐4208626
鸿蒙传说
相关分类