에 따라 : 다음은 내보기 그런 식으로 설계되어
myApp.controller('ExcelViewCtrl', ['$scope', '$http', function($scope, $http) {
$scope.$on("SET_EXCEL_TITLES", function (event, excelCols) {
//this event is never fired
$scope.ExcelCols = excelCols;
});
}]);
두 번째 컨트롤러 인
myApp.controller('MapCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.loadData = function() {
$http.get('/map/GetListDB').success(function (data, status, headers, config) {
//Logic here is working fine, it creates a table named "ExcelCols" which is a table of strings
$scope.$broadcast("SET_EXCEL_TITLES", $scope.ExcelCols);
})
}
}]);
: 여기
는 datas를 보낼 수있는 컨트롤러입니다 컨트롤러가 어떻게 구성되어
$broadcast
메시지가 라우팅 될지를 결정합니다.
documentation
당으로
등록 된 NG 통지 모든 하위 범위 (및 자녀)에 아래 이벤트 이름을 전달합니다. $ rootScope.Scope # $ 청취자에.
이것은 브로드 캐스트를 보내는 컨트롤러가 하위 컨트롤러 html의 상위 html에 정의되어야 함을 의미합니다.
html 구조를 기반으로 $rootScope.$broadcast
을 사용하십시오. $rootScope
을 MapCtrl
에 삽입하고 $broadcast
방법을 호출하십시오.
컨트롤러는 어떻게 인스턴스화됩니까? 'ExcelViewCtrl'과 그 범위가'MapCtrl'의 자식입니까? '$ broadcast'와'$ emit'의 차이점을보십시오. –
아마도 그 점을 오해했을 것입니다. 나는 $ emit이 부모에게 메시지를 보내는 데 사용되며, 모든 컨트롤러에 무언가를 보내는 데 사용되는 방송이라고 생각합니다. –