모달을 여는 응용 프로그램에 버튼이 있습니다. 이 모달은 UI 루트 상태에서 새 URL로 반대되도록 구성됩니다.AngularJS : UI 라우터 모달 - 부모 범위
모달 컨트롤러에서 부모 $ 범위에 액세스해야합니다. 부모 $ scope에는 todolist.add라는 자식 상태에서 액세스해야하는 배열이 있습니다.
부모 $ 범위에 액세스해야하는 이유는 무엇입니까? 왜냐하면 나는 서버를 다시 호출하지 않고 부모 $ scope 데이터를 조작하려고하기 때문입니다.
UI 라우터에서 상위 범위에 액세스하는 가장 좋은 방법은 무엇입니까?
// routes
$stateProvider
.state('todolist', {
url: '/todo-list',
views: {
'@': {
...,
controller: 'ListsController'
}
}
})
.state('todolist.add', {
url: '/list/add',
onEnter: ['$state', '$uibModal', function ($state, $uibModal) {
$uibModal.open({
...,
controller: 'FormListModalController' // <- in this controller I need to access the $scope from the parent
}).result.finally(function() {
...
});
}]
})...
.
.controller('ListsController', function ($scope, ...) {
$scope.lists = []; // there are data in this $scope array
});
.
.controller('FormListModalController', function ($scope, ...) {
$scope.$parent.todolist.lists; // <- in this Modal's Ctrl I need to access the parent $scope (ListsController)
});
https://toddmotto.com/all- about-angulars-emit-broadcast-on-publish-subscribe/ 가장 좋은 방법 중 하나는 이벤트를 브로드 캐스팅하고 부모 범위에서 수신하는 것입니다. 또한 서비스로 데이터를 조작 한 다음 컨트롤러가 서비스에서 데이터를 다시 가져 오도록 이벤트를 브로드 캐스트합니다. – Alburkerk