I am working on sample Angular 2 application , and below is the code of one of my components.
export class ProductComponent implements OnInit {
product:Product;
constructor(private appService: AppService , private router:Router ,private route:ActivatedRoute) {}
ngOnInit()
{
let id:string;
let pid:string;
this.route.params.subscribe( (params) => {
id = params['id'];
pid = params['pid'];
this.appService.GetProduct(id,pid).subscribe( data => {
this.product = data;
});
})
}
In this partcular component , my intention is to read both the route parameters(id , pid) and then make a call to service method. But because there are 2 route parameters to read , the service method is called twice.
Any idea what needs to be modified so that service method is called once ?