title: set and get data from service angular 5
body: <p>I am using angular 5
  my scenario is from one component im setting the data in service and from another component i'm getting that data|</p>
  
  <p>Component- 1:</p>
  
  <pre><code>makeUser(row){
    this.agentsService.setSelectedAgentData(row); // setting the data (row) in agentsService.
    const mrf =  this.modalService.open(MakeUserComponent);    
  }
  </code></pre>
  
  <p>Service:
  declaring the varible in class.</p>
  
  <pre><code>public selectedData:any = {};
  </code></pre>
  
  <p>setter and getter methods are as below</p>
  
  <pre><code>  setSelectedAgentData(selectedTableRowData){
      this.selectedData = selectedTableRowData;
    }
    getSelectedAgentData(){
      return this.selectedData;
    }
  </code></pre>
  
  <p>Component - 2:</p>
  
  <pre><code>  ngOnInit() {
      this.userDetails = this.agentsService.getSelectedAgentData();
      this.roles = this.agentsService.getRolesList();
    }
  </code></pre>
  
  <p>Here the selectedData value is an empty object when I call the method this.agentsService.getSelectedAgentData() from component -2 </p>
  
  <p>Any help would be appreciated.</p>