Reputation: 71
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 ?
But how can i pass the parameter when i select more than one object ?
Upvotes: 1
Views: 326
Reputation: 112
add your products to an array first
productList = [] as any[];
productList.push(product);
this.navCtrl.push(OrderPage,{ productList: productList});
Upvotes: 1
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