ynnhoj24
ynnhoj24

Reputation: 71

How can i pass the selected data objects to another page

When i click the add button

HEllo, how can i pass the selected object data when I want to select more than one and pass it into another page and put it as a list. How can i achieve this ? The product will be the parameter that will be passed into another page But how can i pass the parameter when i select more than one object ?

Upvotes: 1

Views: 326

Answers (2)

mario
mario

Reputation: 112

add your products to an array first

productList = [] as any[];

productList.push(product);

this.navCtrl.push(OrderPage,{ productList: productList});

Upvotes: 1

Dr. X
Dr. X

Reputation: 2930

In angular, you can pass different ways to pass data to other pages

by Query Parameters(if parameters are not secret);

from ts file

this.router.navigate(
   ['/path'], 
   { queryParams: { key1: valu1, key2: value2, key3: value3 } 
});

from html file

<a [routerLink]="['/path']"
   [queryParams]="{ key1: value1, key2: value2, key3: value3 }">
  Something    </a>

path will be like http://localhost:4200/path?key1=value1&key2=value2&key3=value3

You can get by

constructor(private route: ActivatedRoute) {
this.sub = this.route.queryParams.subscribe(params => {
       this.id = +params['id']; // (+) converts string 'id' to a number
    });
}

by Linking to Routes with Parameters

this.router.navigate(['/path', {key1: value1, key2: value2}]);

check the parameters by

constructor(private route: ActivatedRoute) {
this.sub = this.route.params.subscribe(params => {
       this.id = +params['id']; // (+) converts string 'id' to a number
    });
}

Upvotes: 0

Related Questions