×

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: Jun 14, 2017 6:56 PM
Views: 15
Tags: 2 angular
  1.  
  2. 1-
  3. import {Router} from '@angular/router';
  4.  
  5. 2-
  6. template: "<li (click)="onSelect(id)"></li>"
  7.  
  8. 3-
  9. export class AbcComponent {
  10.        
  11.         onSelect(id) {
  12.           this.router.navigate(['/department',id]);
  13.         }
  14. }
  15.  
  16. // receive data in secound component
  17.  
  18. 4-
  19. import { ActivatedRoute } from '@angular/router';
  20.  
  21. export class XyzComponent implements OnInit{
  22.         public depid;
  23.         constructor(private route: ActivatedRoute){}
  24.         /*
  25.         ngOnInit() {
  26.          let id = this.route.snapshot.params['id'];
  27.          this.departmentId = id;
  28.         }
  29.         */
  30.         ngOnInit() {
  31.          let id = this.route.params.subscribe((params: Params)=>{
  32.           let id = parseInt(params['id']);
  33.           this.depid = id
  34.          })
  35.         }
  36.  
  37.  
  38. }