Reputation: 29
I'm setting up routes from my userposts but because posts and users url's are diffrent i can't set it correct up to route correct url of userid who has the post.
constructor(private http: HttpClient, private activatedRoute: ActivatedRoute) { }
pathPosts: string = "https://jsonplaceholder.typicode.com/posts"
pathUsers: string = "https://jsonplaceholder.typicode.com/users"
posts: Post[];
users: User[];
ngOnInit() {
this.getUsers();
this.activatedRoute.params.subscribe(params => {
this.getPosts(params[userid]);
})
}
getPosts(userid: string) {
if (userid) {
this.http.get<Post[]>(this.pathPosts + "posts?userid=" + userid).subscribe(response => {
this.posts = response;
});
} else {
this.http.get<Post[]>(this.pathPosts).subscribe(response => {
this.posts = response;
});
}
}
getUsers() {
this.http.get<User[]>(this.pathUsers).subscribe(response => {
this.users = response;
})
}
ERROR in src/app/post/post.component.ts(24,28): error TS2304: Cannot find name 'userid'.
Upvotes: 0
Views: 41