我已经将URL中的参数传递给我的ionic应用程序
http://localhost:8100/welcompage/overview?brand=bmw
我使用ActivatedRoute来检索作为URL
参数传递的数据constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.params.subscribe(params => {
console.log(params['brand']);
});
}
输出总是"undefined"同时URL
中有参数第一个方法:
let brand = this.route.snapshot.paramMap.get('brand');
第二种方法:
this.route.paramMap.subscribe(
(data) => {
console.log(data.brand)
}
);
当你已经在你的路由url/:brand中定义了品牌参数时,method1或method2适合你的需要。但是如果你使用query params url?brand=value1&property2= value2…您可以使用method3:
获取查询参数数据method3:
this.route.queryParams
.subscribe(params => {
console.log(params); // { brand: "bmw" }
let brand = params.brand;
console.log(brand); // bmw
}
);