ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278.3k

How to generate URL have partid based on part name from list

Dec 23 2019 3:01 PM
problem
How to generate URL have partid based on part name written on text input ?
I have input text on nvabar.Component.html write on it part name as following :
  1. <mat-form-field class="example-full-width">  
  2. <input matInput placeholder="Enter name" [(ngModel)]="partname" >  
  3. </mat-form-field>  
I need when write on text input Transistor part then I will search on list parts and get partid =2 .
then display it in URL as following :
localhost:4200/overview?partid=2
And I can access to Overview Component
  1. navbar.component.ts  
  2.   
  3. export class NavBarComponent implements OnInit {  
  4. public parts = [  
  5.   
  6. {  
  7. id: 1,  
  8. partname: 'hummer',  
  9. },  
  10. {  
  11. id: 2,  
  12. partname: 'Transistor',  
  13. },  
  14. {  
  15. id: 3,  
  16. partname: 'Air',  
  17. }  
  18.   
  19. ];  
  20. ngOnInit() {  
  21. }  
Overview.Component.ts Compoent overview I need to access
  1. export class OverviewComponent implements OnInit {  
  2.   
  3. constructor() {  
  4.   
  5. }  
  6. ngOnInit() {  
  7. //access partid value i will get from URL  
  8. }  
app-routing.module.ts represent routing as following :
  1. const routes: Routes = [  
  2.   
  3. { path: 'overview', component: OverviewComponent },  
  4. { path: '' , redirectTo: '/overview', pathMatch: 'full'}  

Answers (1)