【发布时间】:2016-04-27 15:17:50
【问题描述】:
目前我有:
import { Router } from 'angular2/router';
@Component({...})
export class Index {
constructor(public router: Router) {
this.router.subscribe({...});
}
}
该组件还有其他功能,但与问题无关
我尝试将调试器和 console.log() 放入订阅函数中,但无论我做什么,我都无法发生任何事情。我也尝试将 router.subscribe() 移动到 ngOnInit() ,结果相同。没有。
我需要能够根据 URL 的状态将资源从“帐户”切换到“用户”或其他资源,并进行适当的 API 调用。目前我不明白为什么这不起作用。我有什么明显的遗漏吗?多次订阅路由器有限制吗?我已经在另一个组件中这样做了,它工作正常。
【问题讨论】: