title: angular 2 passing a function var to a different component
body: <p>i am new to angular 2 and i have a question.
  I created a modal as a component called ModalContent and one of its functions is:</p>
  
  <pre><code>@Component({
  selector: 'modal-content',
  templateUrl: './app/d-modal/d.modal.content.component.html',
  styleUrls: [ './app/d-modal/d.modal.content.component.css' ],
  providers: [InMemoryDataService],
  })
  export class ModalContent {
      totalSelected:number;
  
      addM() { 
          let selected = this.m.filter((x) =&gt; x["selected"]);
          let totalSelected = selected.length;
          console.log(totalSelected);
          this.activeModal.close('Close click');
      }}
  </code></pre>
  
  <p>How can I pass the variable <code>totalSelected</code> in the modal component to a function in a totally  different component called form to use it same as the below:</p>
  
  <pre><code>@Component({
  
   moduleId: module.id,
    selector: 'form',
    templateUrl: 'form.component.html',
    styleUrls: [ 'form.component.css' ],
    directives : [ModalContent],`
  
  })`
  
  export class FormComponent {
  @ViewChild(ModalContent) childComp: ModalContent;
      addMForm() {
          const modalRef = this.modalService.open(ModalContent);
           modalRef.componentInstance.name = 'World';`
           this.childComp.addM();
  
      for (var m = 0; m &lt; totalSelected; m++)
      {
          let newGroup = new FormGroup({
            A :new FormControl(),
            B: new FormControl(),
            C: new FormControl(),
            D :new FormControl()
          });
  
  
  
          this.Form.controls.users.push(newGroup);
      }}
  
  }
  </code></pre>
  
  <p>the thing that i want to achieve is to create a number of fields in my form based on the number of selection in the modal component so whatever the user choose in the modal component i want to capture the number in totalselected variable and push it to the form component and use it in the (for) as a counter but it is not working</p>