Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
As shown below in commented, I am finding difficult understand the code can anyone explain to me what this line of code does??

let user = new User();
    user = {...this.frm.value};   // what this line does ??
    
    this.userService.post(user).then(respone => {
      console.log(respone);
    });

---------------------------------------------------------------------	

- deleteUser(user: User): void {
    this.userService.deleteUser(user.id)
      .subscribe( data => {
        this.users = this.users.filter(u => u !== user);      // whats this line does??
      })
  };
 
----------------------------------------------------------------------------------
 
- onSubmit() {
    this.userService.updateUser(this.editForm.value)
      .pipe(first())    // whats this line does??
      .subscribe(
        data => {
          this.router.navigate(['list-user']);
        },
        error => {
          alert(error);
        });
  }


What I have tried:

I copy those line and pasted on google, if I get any help online
Posted
Updated 1-Sep-19 4:52am

1 solution

JavaScript
user = {...this.frm.value};   // what this line does ??
The three dots are called the spread syntax: Spread syntax - JavaScript | MDN[^].

In this specific line of code, the purpose is to copy properties from one object to another[^].

JavaScript
this.users = this.users.filter(u => u !== user); // whats this line does??
.filter is a function on an array[^] that takes a predicate as argument (a function that takes a value as argument and returns true or false) and returns a new array, only keeping the values for which the predicate returned true. Your predicate is u => u !== user so the result of the filtering is an array which all users that are not equal to user.

JavaScript
.pipe(first())
I think this is about this: first · learn-rxjs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900