У меня круговая зависимость между двумя компонентами. Я знаю, что это так, и у меня есть дополнительный охранник, чтобы предотвратить круг. Однако при компиляции я не могу отключить уведомление.
У меня есть приложение чата, и круг происходит потому, что из компонента home
можно открыть компонент profile
. Из компонента profile
у вас есть возможность отправить им текстовое сообщение, теперь, когда вы находитесь в компоненте chat
, вы можете щелкнуть их аватар, и он откроет компонент профиля.
Другой способ войти в этот круг - перейти на вкладку чата и щелкнуть по человеку, которому вы хотите отправить сообщение, а затем щелкнуть его аватар и открыть компонент профиля, который, если вы нажмете «отправить сообщение», откроет * 1007. * компонент
Что я сделал, так это проследил за тем, как они обращаются к странице, и если вы обращаетесь к компоненту profile
из компонента chat
, то вместо открытия компонента chat
вы отклоняете профиль, чтобы вернуться назад. Что работает отлично, однако, это предупреждение о круговой зависимости раздражает.
Есть ли способ предотвратить эту круговую зависимость? Если нет, то как отключить предупреждение?
home.component
this.modalService.openProfile(doctor, ProfileComponent);
profile.component / html
public async openChat(ev: any) {
this.modalService.openChat(this.contact, ChatComponent); //pass reference
}
<ng-container *ngIf="sentFrom === 'chat'; else homePage ">
<ion-button (click)="closeProfile()" color="primary" slot="start"><ion-icon name="paper-plane"></ion-icon>Enviar Mensaje</ion-button>
</ng-container>
<ng-template #homePage>
<ion-button (click)="openChat()" color="primary" slot="start"><ion-icon name="paper-plane"></ion-icon>Enviar Mensaje</ion-button>
</ng-template>
chat.component
public async openProfile() {
this.modalService.openProfile(this.contact, ProfileComponent);
}
//similar guard on the HTML page
Модальные услуги
import { ModalController } from '@ionic/angular';
@Injectable({
providedIn: 'root'
})
export class ModalService {
constructor(private modalCtrl: ModalController) {}
public async openChat(contact: Contact, modal: any) {
const chat = await this.modalCtrl.create({
component: modal,
animated: true,
componentProps: {contact}
});
return await chat.present();
}
public async openProfile(contact: Contact, modal: any) {
const profile = await this.modalCtrl.create({
component: modal,
animated: true,
componentProps: {contact}
});
return await profile.present();
}
public dismiss() {
return this.modalCtrl.dismiss();
}
}
WARNING in Circular dependency detected:
[ng] src/Components/chat/chat.component.ts -> src/Components/profile/profile.component.ts -> src/Components/chat/chat.component.ts
[ng] WARNING in Circular dependency detected:
[ng] src/Components/profile/profile.component.ts -> src/Components/chat/chat.component.ts -> src/Components/profile/profile.component.ts