Is there a better way to pass objects when navigating to a target component using Angular router? Currently, I am using routeParams and stringifying my objects, but I'm not satisfied with this approach. What would an improved solution entail?
export class Overview {
//import {Router} from "@angular/router-deprecated";
constructor(private router:Router) {}
goToElementComponent(elem:Element) {
this.router.navigate(['ElementDetail', {elem: JSON.stringify(elem)}]);
}
}
export class ElementDetail {
// import {RouteParams, Router} from "@angular/router-deprecated";
this.elem : Element;
constructor(private routeParams:RouteParams) {}
ngOnInit() {
var elem = JSON.parse(this.routeParams.get("elem"));
if (elem) {
this.elem = elem;
} else {
this.elem = new Element();
}
}
}