Dev Teywa

Dev Teywa

  • 1.9k
  • 250
  • 30.2k

how to add item from array to class using angular2

Jan 24 2018 11:05 AM
Hello,
I have a user class
 
export class User {
constructor(
public email: string,
public password: string) { this.email=email;this.password=password}
}
 
I'm storing the values of this class in an array like this
 
users :User[]= [
new User('admin@admin.com','adm9'),
new User('user1@gmail.com','a23')
];
 
after I create an add_user function that allows to add a user

add_user(user:User)
{
this.users.push(the problem is here );
console.log(this.users);
this._router.navigate(['login']);
}
 
ho can i do please ?
thanks in advance 
 
 
 
       

Answers (3)