This channel is best of all!! @Venkat Sir : Requesting you to please do some videos for HTML5 and CSS3 as they are must know skills now a days everywhere as a full stack developer. Thanks
Thank you for all your great tutorial series. I really appreciated the course structures, clear explanations and rich project examples. Would you have some development project tutorial about Angular Flex-Layout or Material as well? Thanks again & all the best Rysage
Dear Venkat, I find it very difficult to understand the following block of code in the save() method in employee.service.ts. save(employee: Employee) { if (employee.id === null) { const maxId = this.listEmployees.reduce(function (e1, e2) { return (e1.id > e2.id) ? e1 : e2; }).id; employee.id = maxId + 1; this.listEmployees.push(employee); } else { const foundIndex = this.listEmployees.findIndex(e => e.id === employee.id); this.listEmployees[foundIndex] = employee; } } The first question is regarding the reduce() method. I don't understand what do you mean the reduce() method reduces the array to a single value ? The second and most important question is regarding the reduce() method. Could you kindly explain the logic on how to reduce the listEmployees array into a single value especially on how the provided function is executed for every employee object in the listEmployees array from left-to-right ? The final question is regarding the two lines of code within the else block as shown below. const foundIndex = this.listEmployees.findIndex(e => e.id === employee.id); this.listEmployees[foundIndex] = employee; I don't understand why do we need to replace the existing employee object at the found index with the incoming employee object ? Best regards, Edward
The first question is regarding the reduce() method. I don't understand what do you mean the reduce() method reduces the array to a single value ? The final question is could you kindly explain the logic on how to reduce the listEmployees array into a single value because I don't understand how it works ? The following is the answer for both the above questions : When employee id is null, it implies that we are creating a new employee. When a new employee is created, we need to compute the id property value, before we push that employee object into the array. So to compute the next id value, we first need to identify what is the current maximum id value in the listEmployees array. There are several ways to do this. One way is by using the reduce() JavaScript method. We need to tell the reduce() method on how to compare 2 employee objects to find the object that has the greater id value. So we are passing an anonymous function as a parameter to the reduce() method. This anonymous function(e1, e2), has 2 employee objects and the logic on how to compare these 2 objects and return the object which has greater id value. The reduce() method will then apply this logic to all the elements in the listEmployees array from left to right. So finally when the the reduce method completes execution it will be left with one employee object. This object is the one that has the maximum id value. We then add 1 to that max id value and assign the resulting value to the id property of the employee object that is being pushed into the listEmployees array. The second question is regarding the two lines of code inside the else block. I don't understand why do we need to replace the existing employee object at the found index with the incoming employee object ? As you might already know, else block is executed if id property value of the incoming employee object is not null. This means we have edited an employee object and those details need to be saved. Instead of copying each property value of the incoming employee object into the original employee object in the listEmployees array, we are replacing the existing original object with the incoming object. To do that we first find the original employee object index position in the listEmployees array using findIndex() method. We then use that index position to replace the original employee object in the listEmployees array with the incoming updated employee object.
Thank you very much for your reply. Could you kindly explain the logic on how to compare the 2 employee objects (e1 and e2) and return the object which has greater id value. How the reduce() method will then apply this logic to every element in the listEmployees array from left to right ? In our case, we have three employee objects in the listEmployees array. So is e1 refer to employee Mark and e2 refer to employee Mary ?
Basically we are telling to compare the id property of 2 employee objects and then return the employee object which has the greater id value of those 2 employee objects. So the reduce() will now apply this logic to the first 2 employee objects (Mark and Mary). Mary employee object id value is greater than Mark employee object. So Mary object will then be compared with John employee object. John employee object has greater id value than Mary employee object, so John employee object will finally be returned. In our case we only have 3 employees in the array. Even if you have more than 3 elements in the array, the comparison logic is applied in a similar fashion from left to right and finally returns that one object which has the maximum id value. Hope this clarifies.
Dear Venkat, Regarding the following code, you have mentioned that the employee object is automatically updated because the employee property is holding a reference to the employee object in the EmployeeService. this.employee = this._employeeService.getEmployee(id); Could you kindly please explain what do you mean the employee property is holding a reference to the employee object in the EmployeeService because I don't understand ? May I ask what is a reference ?
This is a basic programming concept. Objects are different from object reference variables. An object reference variable is not an object, rather it's a pointer to an object. It's possible, you may have 2 object reference variables but they may be pointing at the same object. In this case, that's exactly what's happening. this.employee property is a reference variable and pointing at the same object in the array in EmployeeService. Hope this clarifies. If the concept of Objects and Object reference variables is still confusing, I suggest watch the following 2 videos and also read the respective text articles. Why should you override Equals() method th-cam.com/video/IhXWil0kcTo/w-d-xo.html Text Article csharp-video-tutorials.blogspot.com/2012/07/part-58-c-tutorial-why-should-you.html Angular Pure Pipe th-cam.com/video/G7WaP-yoiQg/w-d-xo.html Text Article csharp-video-tutorials.blogspot.com/2018/05/angular-pure-pipe.html
I am using the same form for adding and updating the details but in my case, the parent is a module and child is the component name as userdetails & adduserdetails . In the parent, I have a table for displaying details. At the end of every data row, I have an action button through which I am sending this data row to the child component form for editing the details. But I have no idea how I change the form title when I am going to editing the user details. Please guide me.
This channel is best of all!! @Venkat Sir : Requesting you to please do some videos for HTML5 and CSS3 as they are must know skills now a days everywhere as a full stack developer. Thanks
welcome back Professor Venkat, I always pray for you.Allah bless you
A tip: you can watch movies on InstaFlixxer. Been using them for watching all kinds of movies these days.
@Nolan Coen Definitely, I have been watching on instaflixxer for months myself :)
@Nolan Coen yup, been watching on InstaFlixxer for since november myself :)
@Nolan Coen yea, have been watching on instaflixxer for since november myself =)
@Nolan Coen yea, I have been watching on instaflixxer for since november myself =)
Hello, i am using APIs to retrieve data, and when i get to edit mode of an employee, i get invalid date in the input field of date?
Good job sir,you are great teacher in the world
Thank you for all your great tutorial series. I really appreciated the course structures, clear explanations and rich project examples.
Would you have some development project tutorial about Angular Flex-Layout or Material as well?
Thanks again & all the best
Rysage
much love from South Africa
A very good teacher!
export class BooksService {
books: Array;
constructor(private http: HttpClient) { }
show(title: string, text: string) {
alert(text);
}
get(): Observable {
return this.http.get('fakerestapi.azurewebsites.net/api/books');
export class BooksComponent implements OnInit {
books: Array;
constructor(private bService: BooksService) { }
ngOnInit() {
this.getBooks();
}
getBooks() {
this.bService.get().subscribe((data) => {this.books = data; });
}
}
You are the best sir....
Dear Venkat,
I find it very difficult to understand the following block of code in the save() method in employee.service.ts.
save(employee: Employee) {
if (employee.id === null) {
const maxId = this.listEmployees.reduce(function (e1, e2) {
return (e1.id > e2.id) ? e1 : e2;
}).id;
employee.id = maxId + 1;
this.listEmployees.push(employee);
} else {
const foundIndex = this.listEmployees.findIndex(e => e.id === employee.id);
this.listEmployees[foundIndex] = employee;
}
}
The first question is regarding the reduce() method. I don't understand what do you mean the reduce() method reduces the array to a single value ?
The second and most important question is regarding the reduce() method. Could you kindly explain the logic on how to reduce the listEmployees array into a single value especially on how the provided function is executed for every employee object in the listEmployees array from left-to-right ?
The final question is regarding the two lines of code within the else block as shown below.
const foundIndex = this.listEmployees.findIndex(e => e.id === employee.id); this.listEmployees[foundIndex] = employee;
I don't understand why do we need to replace the existing employee object at the found index with the incoming employee object ?
Best regards,
Edward
The first question is regarding the reduce() method. I don't understand what do you mean the reduce() method reduces the array to a single value ? The final question is could you kindly explain the logic on how to reduce the listEmployees array into a single value because I don't understand how it works ?
The following is the answer for both the above questions : When employee id is null, it implies that we are creating a new employee. When a new employee is created, we need to compute the id property value, before we push that employee object into the array. So to compute the next id value, we first need to identify what is the current maximum id value in the listEmployees array. There are several ways to do this. One way is by using the reduce() JavaScript method. We need to tell the reduce() method on how to compare 2 employee objects to find the object that has the greater id value. So we are passing an anonymous function as a parameter to the reduce() method. This anonymous function(e1, e2), has 2 employee objects and the logic on how to compare these 2 objects and return the object which has greater id value. The reduce() method will then apply this logic to all the elements in the listEmployees array from left to right. So finally when the the reduce method completes execution it will be left with one employee object. This object is the one that has the maximum id value. We then add 1 to that max id value and assign the resulting value to the id property of the employee object that is being pushed into the listEmployees array.
The second question is regarding the two lines of code inside the else block. I don't understand why do we need to replace the existing employee object at the found index with the incoming employee object ?
As you might already know, else block is executed if id property value of the incoming employee object is not null. This means we have edited an employee object and those details need to be saved. Instead of copying each property value of the incoming employee object into the original employee object in the listEmployees array, we are replacing the existing original object with the incoming object. To do that we first find the original employee object index position in the listEmployees array using findIndex() method. We then use that index position to replace the original employee object in the listEmployees array with the incoming updated employee object.
Thank you very much for your reply. Could you kindly explain the logic on how to compare the 2 employee objects (e1 and e2) and return the object which has greater id value. How the reduce() method will then apply this logic to every element in the listEmployees array from left to right ? In our case, we have three employee objects in the listEmployees array. So is e1 refer to employee Mark and e2 refer to employee Mary ?
Basically we are telling to compare the id property of 2 employee objects and then return the employee object which has the greater id value of those 2 employee objects. So the reduce() will now apply this logic to the first 2 employee objects (Mark and Mary). Mary employee object id value is greater than Mark employee object. So Mary object will then be compared with John employee object. John employee object has greater id value than Mary employee object, so John employee object will finally be returned.
In our case we only have 3 employees in the array. Even if you have more than 3 elements in the array, the comparison logic is applied in a similar fashion from left to right and finally returns that one object which has the maximum id value. Hope this clarifies.
Dear Venkat,
Regarding the following code, you have mentioned that the employee object is automatically updated because the employee property is holding a reference to the employee object in the EmployeeService.
this.employee = this._employeeService.getEmployee(id);
Could you kindly please explain what do you mean the employee property is holding a reference to the employee object in the EmployeeService because I don't understand ? May I ask what is a reference ?
This is a basic programming concept. Objects are different from object reference variables. An object reference variable is not an object, rather it's a pointer to an object. It's possible, you may have 2 object reference variables but they may be pointing at the same object. In this case, that's exactly what's happening.
this.employee property is a reference variable and pointing at the same object in the array in EmployeeService. Hope this clarifies.
If the concept of Objects and Object reference variables is still confusing, I suggest watch the following 2 videos and also read the respective text articles.
Why should you override Equals() method
th-cam.com/video/IhXWil0kcTo/w-d-xo.html
Text Article
csharp-video-tutorials.blogspot.com/2012/07/part-58-c-tutorial-why-should-you.html
Angular Pure Pipe
th-cam.com/video/G7WaP-yoiQg/w-d-xo.html
Text Article
csharp-video-tutorials.blogspot.com/2018/05/angular-pure-pipe.html
I am using the same form for adding and updating the details but in my case, the parent is a module and child is the component name as userdetails & adduserdetails . In the parent, I have a table for displaying details. At the end of every data row, I have an action button through which I am sending this data row to the child component form for editing the details. But I have no idea how I change the form title when I am going to editing the user details. Please guide me.
Why edit employee is success before you add new save method implementation (check if id is null or exist in db)?
Good evening sir..love your videos sir.. Sir please can you create a video on creating a facebook type comment system in angularjs ,c# and sqlserver
sir how can i edit and update the image using angular and php
how to fill data in text box and select tag when edit data
Venkat for President!
can you do a series on advance Reactjs and firebase together?