0

Given two angular 2 components :

  • ListItemsComponent.
  • ShowItemComponent.

When user selects an item from ListItemComponent he must be redirected to ShowItemComponent by receiving selected item object.

Knowing that both components are present in the same tree level.

What is the best way to past object item from listItemsComponent to ShowItemComponent ?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
user2080105
  • 1,642
  • 4
  • 18
  • 27

1 Answers1

0

you can use Router.navigate and give it the path of other component with the item id in ListItemComponent in constructor declare the Route constructor( private _router: Router)

 this._router.navigate(['..../ShowItemComponent', {itemId:itemId}])

and in the ShowItemComponent put ActivatedRoute

constructor(private _activateRoute: ActivatedRoute){

      this._activateRoute.params.subscribe(
          (param: any) => {
            let itemId = param['itemId'];
    });
}
Yousef Al Kahky
  • 703
  • 1
  • 8
  • 23