我需要将电流传递userId
给routerlink
inborrow_list component
我声明的userId
方式borrow_list component
userId: number;
constructor(private authService: AuthService, private bookService: BookService,
private route: ActivatedRoute, private alertify: AlertifyService) { }
ngOnInit() {
this.userId = this.authService.decodedToken.nameid;
this.route.data.subscribe(data => {
this.books = data['books'].result;
this.pagination = data['books'].pagination;
});
this.borrowParam = 'loan';
console.log(this.userId); // this one return 26
}
然后我尝试使用传递userId
给另一个组件routerlink
<div class="row">
<div *ngFor="let b of books" class="col-sm-6 col-md-4 col-lg-4 col-xl-2">
<app-book-card [book]="b"></app-book-card>
<button class="btn btn-primary" [routerLink]="
['/browse/book/',this.userId,'/content/', b.id]" style="width: 75px">Read
</button>
</div>
</div>
但它似乎不起作用,没有错误,但它引导我回到主页
当我尝试对链接进行硬编码并且它按预期工作时,即
[routerLink]="['/browse/book/26/content/', b.id]"
我的routes.ts
{path: 'browse/book/:id/content/:bookId', component: Book_contentComponent, resolve: {book: BookContentResolver}}
我想我在某个地方做错了吗?