为什么我们在ActivatedRoute中使用paramMap而不是简单地使用可观察的参数?
该摘录摘自《 Angular入门》网站(https://angular.io/start)。我只是想知道此实现背后的问题...谢谢!
export class ProductDetailComponent implements OnInit {
product;
constructor(private route:ActivatedRoute, private cartService:CartService) { }
ngOnInit() {
this.route.paramMap.subscribe(params => {
this.product = products[+params.get('productId')];
});
}
addToCart(product) {
window.alert(product.name + " has been added to the cart.");
this.cartService.addToCart(product);
}
}