0
votes

I just want to make the transition to id. Well, or something like that (I just do not know how to explain it). In general, when you press a button to go to a specific user, there is such an error:

ERROR TypeError: this.route.params.flatMap is not a function

at UserShowComponent.ngOnInit (user-show.component.ts:31)

at checkAndUpdateDirectiveInline (core.js:12369)

at checkAndUpdateNodeInline (core.js:13893)

at checkAndUpdateNode (core.js:13836)

at debugCheckAndUpdateNode (core.js:14729)

at debugCheckDirectivesFn (core.js:14670)

at Object.eval [as updateDirectives] (UserShowComponent_Host.ngfactory.js? [sm]:1)

at Object.debugUpdateDirectives [as updateDirectives] (core.js:14655)

at checkAndUpdateView (core.js:13802)

at callViewAction (core.js:14153)

How can this be remedied?

import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Angular2TokenService } from "angular2-token";
import { UserService} from '../../../../services/user/user.service';
import { User } from '../../../../models/user.model';

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

  id: number;
  routeId: any;

  constructor(
    private authTokenService: Angular2TokenService, 
    private route: ActivatedRoute,
    private servUser: UserService,
  ) { }

  @Input() user: User;

  ngOnInit() {
    this.routeId = this.route.params.subscribe(
      params => {
        this.id = +params['id'];
      }
    )
    let userRequest = this.route.params.flatMap((params: Params) => 
        this.servUser.getUser(+params['id']));
    userRequest.subscribe(response => this.user = response.json());
  }

}
1
are you using Angular 6 & rxjs 6?Tim Martens
What version of angular and rxjs are you using ?CornelC
rxjs 5.5.6 angular 5.2.0user9934609
@user9934609: If you found any answer is helpful then please used to do practice to upvote the answer because that dev has invested his/her time to solve your problem.baj9032

1 Answers

2
votes

Just use mergeMap insted of flatMap

import 'rxjs/add/operator/mergeMap';

Take a look rxjs flatmap missing.