我只是想转换到 id。嗯,或者类似的东西(我只是不知道如何解释)。一般来说,当你按下一个按钮去特定用户时,会出现这样的错误:
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)
如何解决这个问题?
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());
}
}
最佳答案
关于javascript - 错误类型错误: this.route.params.flatMap不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50832143/