I've created a TypeScript model within my Angular application and initialized an object with that model. However, when passing the object through routing to the second component (UserComponent), the associated types are not available as shown in the image. Below are the relevant code snippets. You can also find the StackBlitz demo at: https://stackblitz.com/edit/tsmodel-test
Model
export class UserModel{
name: string;
id: number;
}
1st Component
export class HelloComponent {
user = new UserModel();
constructor(private router: Router){}
ngOnInit() {
this.user.name = 'abdc';
this.user.id = 23232
console.log(this.user)
}
btnClick() {
this.router.navigate(['user'], { state: {data: this.user} });
}
}
2nd Component
export class UserComponent implements OnInit {
constructor(private route: ActivatedRoute) {}
user;
ngOnInit() {
console.log('Component2')
console.log(history.state.data);
this.user = history.state.data;
}
}
Output