【发布时间】:2017-05-10 09:58:25
【问题描述】:
我正在开发示例 Angular 2 应用程序,下面是我的一个组件的代码。
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;
});
})
}
在这个特定的组件中,我的意图是读取两个路由参数(id,pid),然后调用服务方法。 但是因为要读取2个路由参数,所以服务方法被调用了两次。
知道需要修改什么以便调用一次服务方法吗?
【问题讨论】:
-
你的说法
this.appService.GetProduct()被调用了两次,因为有两个路由参数?
标签: angular