What if while using snapshot method we navigate back to the same component and do not write that code (which is written inside ng_on_init method) inside ng_on_init method..? Will it work fine?
Nice one but in real world app IDs are not going to created like this approach, then how to tackle this id in employee details component.I will be so grateful if you give me the answer regarding this.Thanks.
i still did not get why this_router.navigate is not changing employee to next employee. this is what job of _router.navigate method is to refresh or route the page.
So far, a great tutorial but this particular lesson is flawed. First, this assumes that the IDs will be in exact order (1, 2, 3, 4, 5...nth). It's a bad idea to assume this. If an employee is deleted (i.e. ID=4), then the code breaks because it is told to go up incrementally. Second, the ceiling of the conditions to check for before it loops back to the beginning should be done by calling the service data array length. Instead of hard-coding it to 3 or any number. Again, what happens if someone gets deleted or added? employees: Employee[]; ngOnInit() { this.employees = this._employeeService.getEmployees(); this._route.paramMap.subscribe(params => { this._id = +params.get('id') this.employee = this._employeeService.getEmployee(this._id); }); } viewNextEmployee() { if( this._id < this.employees.length ){ this._id = this._id + 1; //this should use the this.employees index this._router.navigate(['/employees', this._id]) } else { this._id = 111111; //this should return you to the employees index = 1 } } Third, even if you used the IDs to find if this._id < the.employees.length. That will fail if the ID numbers do not start from 1. In other words, if the employee's IDs are ID=11111, ID=22222, and ID=677483. Then the logic fails because all of those IDs are > 3 which is the.employees.length. I recommend using index for this logic But great job nonetheless. If you could re-do this portion with those fixes, you will have a complete lesson.
thanks! I appreciate your hard work!
how to give dynamic value in if condition eg. (this._id < arrayname.length) instead of (this._id < 3)
Thanks Sir! for making this video.
This cleared me everything.
What if while using snapshot method we navigate back to the same component and do not write that code (which is written inside ng_on_init method) inside ng_on_init method..? Will it work fine?
Nice one but in real world app IDs are not going to created like this approach, then how to tackle this id in employee details component.I will be so grateful if you give me the answer regarding this.Thanks.
hello, u helped me today....really with update route.navigation. Where can i find ur full list of angular videos??
can i use third party jquery library in our angular 5 project. Please give me a solution. example jquery datatable plugin in angular 5 project.
Best one, LIKE
can i use third party jquery library in our angular 5 project. Please give me a solution.
very thanks
i still did not get why this_router.navigate is not changing employee to next employee. this is what job of _router.navigate method is to refresh or route the page.
Please give me steps so that we don't have to hardcode the values when the list enters the last item
very good
super
So far, a great tutorial but this particular lesson is flawed.
First, this assumes that the IDs will be in exact order (1, 2, 3, 4, 5...nth). It's a bad idea to assume this. If an employee is deleted (i.e. ID=4), then the code breaks because it is told to go up incrementally.
Second, the ceiling of the conditions to check for before it loops back to the beginning should be done by calling the service data array length. Instead of hard-coding it to 3 or any number. Again, what happens if someone gets deleted or added?
employees: Employee[];
ngOnInit() {
this.employees = this._employeeService.getEmployees();
this._route.paramMap.subscribe(params => {
this._id = +params.get('id')
this.employee = this._employeeService.getEmployee(this._id);
});
}
viewNextEmployee() {
if( this._id < this.employees.length ){
this._id = this._id + 1; //this should use the this.employees index
this._router.navigate(['/employees', this._id])
} else {
this._id = 111111; //this should return you to the employees index = 1
}
}
Third, even if you used the IDs to find if this._id < the.employees.length. That will fail if the ID numbers do not start from 1. In other words, if the employee's IDs are ID=11111, ID=22222, and ID=677483. Then the logic fails because all of those IDs are > 3 which is the.employees.length.
I recommend using index for this logic
But great job nonetheless. If you could re-do this portion with those fixes, you will have a complete lesson.
Below code works fine without subscribe.
this.employee= this._employeeservice.getEmployee(this._id);
this._router.navigate(['/employees',this._id]);