Home > Blockchain >  router not working in Angular Property route does not exist on type
router not working in Angular Property route does not exist on type

Time:11-12

I have following code :

import { ActivatedRoute } from '@angular/router';
..
..
export class ChangepasswordComponent implements OnInit {
..
  constructor(public fb: FormBuilder,
    route: ActivatedRoute, private http: HttpClient,private toastr: ToastrService) { 
    this.changePasswordForm = this.fb.group({
    .......
    }, {  validator: ConfirmedValidator('password', 'password_confirmation') })
    route.queryParams.subscribe((params) => {
      this.changePasswordForm.controls['passwordToken'].setValue(params['token']);
    })

  }
  onSubmit(){
 this.route.navigate(['home']);
}

route.queryParams is working when retrieving value from url quesry string but onSubmit function this.route.navigate(['home']); does not work and error it shows is Property route does not exist on type.....

Thanks

CodePudding user response:

You are using improper dependency injection:

constructor(
    ...,
    route: ActivatedRoute,
    ...
) { }

Change it to:

constructor(
    ...,
    private route: ActivatedRoute,
    ...
) { }

UPDATE: if you want to navigate router, you have to inject Router from '@angular/router' and use it:

import { ActivatedRoute, Router } from '@angular/router';
constructor(
    ...,
    private route: ActivatedRoute,
    private router: Router
    ...
) { }
this.router.navigate(['home']);
  • Related