샘플 Angular 2 응용 프로그램에서 작업 중이며 아래에 내 구성 요소 중 하나의 코드가 나와 있습니다.각도 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;
});
})
}이 partcular 구성 요소에서
, 내 의도는 두 경로 매개 변수 (ID, PID)를 읽고 다음 서비스 메서드를 호출하는 것입니다. 그러나 읽을 경로 매개 변수가 2 개이므로 서비스 메서드가 두 번 호출됩니다.
서비스 메소드를 한 번 호출하도록 수정해야 할 사항은 무엇입니까?
두 개의 라우트 매개 변수가 있기 때문에'this.appService.GetProduct()'가 두 번 호출된다고 말하는가? – inspired