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());
}
}