0
votes

I am using ActivatedRoute for passing id to another route. But when i use snapshot like:

let studentCode = this._activatedroute.snapshot.params['id']

it gives an error: Property 'snapshot' does not exist on type 'typeof ActivatedRoute'. here id is the id to be passed that I used in ngFor iteration.

Full component code where activated route is used:

import { Component, OnInit } from '@angular/core';
import{ StudentHttpServService } from '../show-students/student-http-serv.service';
import {Router, ActivatedRoute} from '@angular/router';
import {Inject} from '@angular/core';

@Component({
  selector: 'app-classes-component',
  templateUrl: './classes-component.component.html',
  styleUrls: ['./classes-component.component.css']
})
export class studentDetailsComponent implements OnInit {

  constructor(@Inject(StudentHttpServService) private __astudentHttpServService: StudentHttpServService, @Inject(ActivatedRoute) private _activatedroute = ActivatedRoute, @Inject(Router) private _router:Router) { 

   }


  ngOnInit() {

//this._StudentHttpServService.getstudentDetailsHttpSrv()
let studentCode = this._activatedroute.snapshot.params['id']

  }

}

Pls let me know if i need to give code for router in app.module.ts or the iteration code (html and ts files). Thanks in advance.

1

1 Answers

2
votes

You need to use : instead of =

 @Inject(ActivatedRoute) private _activatedroute : ActivatedRoute

Corrected Code:

 constructor(@Inject(StudentHttpServService) private __astudentHttpServService: StudentHttpServService, @Inject(ActivatedRoute) private _activatedroute : ActivatedRoute, @Inject(Router) private _router:Router) { 

   }