2016-09-02 1 views
0

내가 컨트롤러에서 데이터를 얻을 모달 창입니다 다른 컨트롤러의 범위에 넣어 수있는 방법에 대한 질문이 있습니다 ... 모달 창에서 다른 컨트롤러의 데이터로 작업하는 방법은 무엇입니까?

내가 설명 할 것 : 여기

가 열립니다 내 이벤트입니다 대화 상자 창 (각 스트랩 모달) :

openDialog() { 
    this.$modal({ 
     show: true, 
     html: true, 
     placement: 'center', 
     type: 'large', 
     templateUrl: 'tmpl.html', 
     controller: myController 
    }); 
} 

이 내 모달 창 템플릿 (tmpl.html)입니다 :

<div class="modal-body" id="modal-body"> 
    <my-directive></my-directive> 
</div> 

내가 사용으로 웹 팩, 나는 주하는 index.js

여기

이 지침의 내 템플릿의 작은 예입니다 내 지시어와 모듈을 초기화 :

constructor($scope) { 
    super($scope); 

    this.$scope = $scope; 

    this.num = 10; 
} 

:

여기
<span class="some-name">{{$ctrl.num}} </span> 

내 다른 컨트롤러입니다 따라서, 스팬에 10이 있다는 것을 알 수 있듯이 다른 컨트롤러에서 데이터를 가져와야합니다. 즉, 데이터 = [ 'asd', 'apple']를 저장합니다. 등등

더 좋은 방법이 있습니까?

답변

0

질문을 올바르게 이해하면 모달 옵션에 범위를 추가하여 상위 컨트롤러의 범위를 모달에 전달할 수 있습니다. 아래 참조 :

this.$modal({ 
     show: true, 
     html: true, 
     placement: 'center', 
     type: 'large', 
     templateUrl: 'tmpl.html', 
     controller: myController, 
     scope: $scope 
    }); 

그게 전부입니까?

+0

확인이 데이터를 얻을 수 modal

openDialog() {에서 myController에서 다음

this.$modal({ show: true, html: true, placement: 'center', type: 'large', templateUrl: 'tmpl.html', controller: myController, resolve : { objData{ dataFromCtrl : $scope.dataFromAnoterCtrl// you can fetch data here either from parent scope or factory/service. } } }); } 

resolve 속성을 사용할 수 있습니다, 그 시도했다 ,하지만 전혀 도움이되지 못했습니다. = ( – Costa

+0

{{$ ctrl.num}}에 10을 표시합니까? 귀하의 질문에서 ell. – defaultcheckbox

+0

네, 1 – Costa

0

당신은

.controller('myController',function(objData){ 
    console.log(objData.dataFromCtrl); // you can get data from another controller in this modal controller. 
}) 
+0

답장을 보내 주셔서 감사합니다.하지만 데이터를 업데이트해야하기 때문에 데이터를 업데이트해야합니다 (데이터가 언제든지 업데이트 될 수 있기 때문에). 그러면 서버가 다시 열릴 때만 업데이트됩니다. – Costa