title: angular 5 save form data in modal class in an array and show it in table
body: <p>I want to save form data in model class and show it in table. 
  once form submited. I pushing the data into class by this.user.addOject() method. but the array always showing last submitted form values only. </p>
  
  <p>after mentioned edits by sajeet: I got StaticInjectorError</p>
  
  <p><strong><em>this.user.getUsers();
  the array data is showing the last submitted form data only.
  {userid: 1, firstName: "ffrere", lastName: "trtr", mobile: "355667676878", accsprofile: Array(1)}</em></strong></p>
  
  <p>this is my model class</p>
  
  <pre><code>export interface IUser {
      userid: number;
      firstName: string;
      lastName: string;
      mobile: string;
      accsprofile: string[];
  }
  @Injectable()
  export class UserService {
      user: IUser;
      userlist: Array&lt;object&gt; = [];
  
      constructor() {}
  
      addOject(): void {
         this.user = user;
         this.userlist.push(this.user);
       }
  
      getUsers(): any {
          return this.userlist;
      }
  }
  </code></pre>
  
  <p><strong>UserDiaologue.component.ts</strong></p>
  
  <pre><code>export class UserdialogueComponent implements OnInit {
  
    userList: IUser[];      
    user: Usermodel;
  
    constructor(private dialog: MatDialog, private user: UserService) { }
  
    ngOnInit() {
    }
    openDialog() {
  
      const dialogConfig = new MatDialogConfig(); 
      const dialogRef = this.dialog.open(UserformComponent, dialogConfig);
  
      dialogRef.afterClosed().subscribe(result =&gt; {    
        const userData = {
          userid: result.data.userid,
          firstName: result.data.userid,
          lastName: result.data.userid,
          mobile: result.data.userid,
          accsprofile: result.data.userid
        };           
        this.user.addOject(userData);         
        console.log(this.user.getUsers()); // always showing last inserted record.         
      });
    }
  }
  </code></pre>
  
  <p><strong><em>the array is showing only the last entered form data.</em></strong></p>