Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nilesh Yadav
Added: Jun 14, 2017 6:43 PM
Modified: Jan 31, 2018 12:10 PM
Views: 42
Tags: angular2
  1. 1-
  2. import {Router} from '@angular/router';
  3.  
  4. 2-
  5. template: "<li (click)="onSelect(id)"></li>"
  6.  
  7. 3-
  8. export class AbcComponent {
  9.        
  10.         onSelect(id) {
  11.           this.router.navigate(['/department',id]);
  12.         }
  13. }
  14.  
  15. // receive data in secound component
  16.  
  17. 4-
  18. import { ActivatedRoute } from '@angular/router';
  19.  
  20. export class XyzComponent implements OnInit{
  21.         public depid;
  22.         constructor(private route: ActivatedRoute){}
  23.         /*
  24.         ngOnInit() {
  25.          let id = this.route.snapshot.params['id'];
  26.          this.departmentId = id;
  27.         }
  28.         */
  29.         ngOnInit() {
  30.          let id = this.route.params.subscribe((params: Params)=>{
  31.           let id = parseInt(params['id']);
  32.           this.depid = id
  33.          })
  34.         }
  35.  
  36.  
  37. }