저는 AngularJS와 잘 어울립니다. 그리고 저의 투쟁에서 저는 $ broadcast/$ emit을 과용했습니다. 과거 백본과 함께 작업 한이 서비스는 앵커리지 외부의 디커플링 된 구성 요소에 대한 표준 goto 인 pubSub의 자연스러운 대체품처럼 보입니다.Idiomatic AngularJS modal
이 경우 네트워크 이벤트 및 사용자 입력에 대한 응답으로 모달 오버레이를 렌더링하려고합니다. 이 즉 - 나는 서로이 구성 요소의 가시성을 변경 가야하는 방법을
<div data-ng-controller="ModalCtrl" class="modal {{visibility}}">
<h2 data-ng-bind="modal.title"></h2>
</div>
:
angular
.module("app.controllers")
.controller("MyCtrl", function ($scope, $rootScope, ModalCtrl) {
$scope.handleClick = function() {
// this:
$rootScope.$broadcast("modal", {
title: "ClickHandler",
visibility: "is-visible"
});
// or this? modify scope directly
$rootScope.modal = {
title: "ClickHandler",
visibility: "is-visible"
};
// or this? - assuming I can pass it in as a dependency
ModalCtrl.show({title: "ClickHandler});
};
});
이것은 IMHO에 대한 좋은 질문이지만 SO에 속합니다. – Pete
MVW Angular의 패턴에서는 분리 된 컨트롤러를 통신하는 방법을 찾는 것이 바람직하지 않습니다. 'ModalCtrl'과 다른 컨트롤러에 주입 할 수있는 매개 서비스를 만들 수 있습니다. – blint
몇 가지 코드로 그 접근법을 보여줄 수 있습니까? – sunwukung