我试图在路由URL上传递JSON,这是我的
app.route.ts代码
{path: 'calculator', component: CalculatorComponent,data : {some_data : null}},
和我的数据路由代码是
this.router.navigate(['/home/calculator', {some_data:this.loanData}]);
和calculator.ts有oninit方法代码就像这样
import {ActivatedRoute} from '@angular/router';
constructor(private route: ActivatedRoute) {}
sub
ngOnInit() {
this.sub = this.route
.data
.subscribe(v => console.log(v));
}
输出就像这样
{ “some_data”:空}
问题是它没有显示json,我从ts第一个组件传递
答案 0 :(得分:1)
<ion-content padding>
<div id="floating-panel">
<b>Start: </b>
<ion-item>
<ion-input (ionFocus)="showAddressModalstart()" (ionChange)="calculateAndDisplayRoute()" [(ngModel)]="start" type="text" placeholder="Delivery Origin"></ion-input>
</ion-item>
<br>
<b>End: </b>
<ion-item>
<ion-input (ionFocus)="showAddressModalend()" (ionChange)="calculateAndDisplayRoute()" [(ngModel)]="end" type="text" placeholder="Delivery Dropoff"></ion-input>
</ion-item>
<br>
</div>
<div #map id="map"></div>
</ion-content>
答案 1 :(得分:0)
你能尝试使用它,这应该有用,希望如此
app.route.ts代码
{path: 'calculator', component: CalculatorComponent},
以及您的路由代码
let someData = {
this.loanData
};
this.router.navigate(['/home/calculator/'+someData]);
和calculator.ts有oninit方法代码就像这样
import {ActivatedRoute} from '@angular/router';
constructor(private route: ActivatedRoute) {}
sub
ngOnInit() {
this.route.params
.subscribe(data => {
this.sub = data;
console.log(this.sub);
});
}