I could use some advice how to approach this problem I'm facing. To explain this best possible for you I have created a main component:
@Component({
selector: 'main-component',
providers: [...FORM_PROVIDERS, MainService, MainQuoteComponent],
directives: [...ROUTER_DIRECTIVES, CORE_DIRECTIVES, RouterOutlet, MainQuoteComponent ],
styles: [`
agent {
display: block;
}
`],
pipes: [],
template: `
**Html hidden**
`,
bindings: [MainService],
})
@RouteConfig([
{ path: '/', name: 'Main', component: MainMenuComponent, useAsDefault: true },
{ path: '/passenger', name: 'Passenger', component: PassengerComponent },
])
@Injectable()
export class MainComponent {
bookingNumber: string;
reservation: Reservation;
profile: any;
constructor(params: RouteParams, public mainService: MainService) {
this.bookingNumber = params.get("id");
this.mainService.getReservation(this.bookingNumber).subscribe((reservation) => {
this.reservation = reservation;
});
this.profile = this.mainService.getUserDetails();
}
}
This component retreive a booking from the api and save it in the reservation object you see (It has a type of Reservation which is a class that looks like this)
export class Reservation {
constructor(
public Id: number,
public BookingNumber: string,
public OutboundDate: Date,
public ReturnDate: Date,
public Route: string,
public ReturnRoute: string,
public Passengers: string,
public Pet: string,
public VehicleType: string,
public PassengersList: Array<Passengers>
) { }
}
When I click the button Passenger, It will redirect to the passenger page Main/passenger, but here I need to send the reservation object (the whole one) or just the PassengerList (the array).
Do any know if its possible to do this with route params or with the router-outlet? Any suggestions?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…