나는 $ 범위를 사용하고 $ 내 ListController에서 방출 달러 (A $)의 rootScope를 트리거 할 MainController의 이벤트 (각 1.3)에 $가 :..왜 rootscope.on이 트리거되지 않습니까?
(function() {
'use strict';
angular
.module('mymodule.faultlist')
.controller('MainController', ['$rootScope', function ($rootScope) {
$rootScope.$on('newViewLoaded', function (event, metadata) {
$rootScope.metadata = metadata;
console.log('hello metacontroller metadata', metadata);
});
}])
.controller('ListController', ['faultlistservice', 'faultListConstants', '$scope', '$timeout', '$rootScope',
function (faultlistservice, faultListConstants, $scope, $timeout, $rootScope) {
$timeout(function() {
$scope.$emit('newViewLoaded', {
'title': faultListConstants.meta.title,
'description': faultListConstants.meta.description
});
}, 100);
}]);
})();
이것은 index.html을 대략 모습입니다 같은 :
.
.
<head ng-controller="MainController">
<div class="container main-content" ui-view >
</div>
..
이것은 트리거되지 않습니다. $ rootScope. $ 블록을 ListController로 옮긴 다음 $ rootScope. $ on이 트리거됩니다. 왜 이것이 MainController에서 작동하지 않습니까? 아니면 이것을 구현하는 더 좋은 방법이 있습니까?
@TheHeadRush 같은 질문입니다! –
ListController 인 경우 MainController 부모입니까? HTML을 공유 할 수 있습니까? –
예 MainController는 맨 위에 정의되어 있습니다. 즉 head 태그에 정의되어 있습니다. ListController는 ui-view (ui-router) 내에 있습니다. MainController는 stateprovider에 정의되어 있지 않습니다. –