На самом деле вы импортируете FormComponent как тип в CanDeactivateGuard. Но вы передаете Компонент Сообщения. Возможно, Angular может выдать ошибку, но этого не происходит.
Чтобы пояснить, я написал некоторый код.
component: MessagesComponent, // this is the component which you're passing to canDeactivate
canDeactivate: [CanDeactivateGuard], // you are passing the messages component to the canDeactivate method
...
canDeactivate(
component: FormComponent, // <- you have FormComponent as a type, but this method actually is receiving MessagesComponent
)
Если вы хотите увидеть компонент формы в браузере консоль, вам нужно передать его.
component: FormComponent,
canDeactivate: [CanDeactivateGuard],
...
canDeactivate(
component: FormComponent, // <- now you can see your form component, and the type is useful to see all the properties and methods which form component has inside itself
)
В вашем случае вы можете использовать дочерний декоратор view, чтобы получить дочерний компонент и использовать его в охране.
export class MessagesComponent {
@ViewChild(FormComponent) formComponent: FormComponent;
}
...
component: MessagesComponent,
canDeactivate: [CanDeactivateGuard],
...
canDeactivate(
component: MessagesComponent,
) {
console.info('magic', component.formComponent);
}