title: How to pass multiple(2 or many) variables through behaviour subject in angular
body: <p>I am new to rxjs. In my application i have encountered a situation of passing username and password values from one component to another(In angular). Would you please help me passing these variables from one component to another component through behaviour subject with a neat basic example.
  I have a class which stores the userdetails
  UserInformation.ts as follows</p>
  
  <pre><code>export class UserInformation {
      username: string;
      constructor() {
      }
  }
  </code></pre>
  
  <p>I have a service as follows.
  User-information.service.ts</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { UserInformation } from '../UserInformation';
  @Injectable()
  export class UserInformationService {
    userData:UserInformation;
    variable:string='ServiceVariable';
    constructor() {
      this.userData = new UserInformation(); 
     }
    getUserData()
    {
      return this.userData;
    }
    setUserData(userData:UserInformation)
    {
      this.userData.username=userData.username;
      console.log(this.userData.officeLocation);
    }
  }
  </code></pre>
  
  <p>In my FirstComponent.ts I have the following code.This getVALuesFromForm method is used to get the username from the form.</p>
  
  <pre><code>getValuesFromForm()
     {
       this.enteredUser.username = this.loginform.get('Username').value;
       console.log(this.enteredUser.username);
       this.service.setUserData(this.enteredUser);     
     }
  </code></pre>
  
  <p>In my secondComponent.ts I have the following code.</p>
  
  <pre><code>import { Component, OnInit , Input , Output  } from '@angular/core';
  import { UserInformation } from '../UserInformation';
  import  { UserInformationService }   from '../services/user-information.service';
  import { Injectable } from '@angular/core';
  @Component({
    selector: 'app-nav-bar-component',
    templateUrl: './nav-bar-component.component.html',
    styleUrls: ['./nav-bar-component.component.css'],
    providers:[UserInformationService]
  })
  @Injectable()
  export class NavBarComponentComponent implements OnInit {
     userInfo:UserInformation;    
    constructor(public service:UserInformationService) {
      this.userInfo=service.getUserData();
      console.log(service.userData.username);
      console.log(this.userInfo.username);
     }
    ngOnInit() {
    }
  }
  </code></pre>
  
  <p>Now my question is how do we pass these variables from First Component to Second Component with the help of Behaviour Subject in Rxjs</p>