2016-08-29 3 views
0

$ 컨트롤러의 범위를 만들 수있는 방법은 두 개의 모듈과 응용 프로그램 1 프로젝트가 2 문서다른 컨트롤러 범위

각 프로젝트가 많은 문서를 가지고 있는데이 프로젝트 테이블에서 하나 개의 프로젝트를 선택하면 내가 원하는 그 문서의 각 모듈에 대한

나는 문서의 가 적절한 문서 정보 폼 데이터베이스를 얻을 내가

문서 테이블에 그것을 채우기 기능이 controller.js service.js 및 controller.js를 만들어 표시 이 함수를 사용하여 g 어떤 프로젝트가 문서를 얻을 내가 객체 documentCtrl projectCtrl에서이 함수를 호출 할 때 문서 테이블

var projectCtrl = this; 
projectCtrl.toggleSelection = function indexof(row){ 

    var documentController = $controller('documentsListController',{ 
     $scope : 'what I have to use here??' 
    }); 

    documentController.callServer(row.projectId); 
} 

에 표시 할 때 선택 프로젝트 테이블에 내 테이블

var documentCtrl = this; 
documentCtrl.callServer = function callServer(projectId) { 

     return documentsService.getDocuments(projectId).then(function(result){ 
       documentCtrl.displayed = result.documents; 
     }); 
    } 

에 등 데이터를 내가 원한다. 가득 표시하지만이 필요한 모든

callServer(projectId) { 

     return documentsService.getDocuments(projectId).then(function(result){ 
       documentCtrl.displayed = result.documents; 
     }); 
전화

그래서 난 컨트롤러간에 communicat하지 않을 테이블이 비어있어

적합한 값으로 documentCtrl.displayed 채우고 제어기 사이에서 통신하는 여러 가지 방법이있다

<div id="documentsList" ng-controller="documentsListController as doc" > 
<tr ng-repeat="row in doc.displayed"> 
     <td>{{row.documentId}}</td> 
     <td>{{row.documentName}}</td> 
     <td>{{row.documentExtension}}</td> 
</tr> 
</div> 

답변

1

표에 표시.

  • 서비스
  • 이벤트
  • 전문가

가장 쉬운 한 - 서비스. documentsService을 호출하면 반환 된 데이터를 해당 서비스 내의 변수에 저장할 수 있습니다. 그리고 그 서비스가 주입 될 모든 컨트롤러에서 사용할 수 있습니다.

var documentCtrl = this; 
documentCtrl.callServer = function callServer(projectId) { 

    return documentsService.getDocuments(projectId).then(function(result){ 
      documentCtrl.displayed = result.documents; 
      documentsService.documents = result.documets; 
    }); 
} 

두 번째 컨트롤러에 서비스를 삽입하면 첫 번째 컨트롤러에서 호출되고 결과는 두 번째 컨트롤러에서도 사용할 수 있습니다.

+0

감사합니다. 질문을 업데이트합니다. –

관련 문제