Skip to content

Instantly share code, notes, and snippets.

@ctfrancia
Created November 7, 2019 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctfrancia/5ce346b3ee228eb1d75b3306f701c71d to your computer and use it in GitHub Desktop.
Save ctfrancia/5ce346b3ee228eb1d75b3306f701c71d to your computer and use it in GitHub Desktop.
Triangle of Circular dependency
import { Component } from '@angular/core';
import { ModalService } from '../../componentServices/modal/modal.service';
@Component({
selector: 'app-chat',
templateUrl: './chat.component.html',
styleUrls: ['./chat.component.scss'],
})
export class ChatComponent {
private modalService: ModalService;
public constructor(modalService: ModalService) {
this.modalService = modalService;
}
public async openProfile(): Promise<void> {
this.modalService.openProfileComponent(this.contact);
}
public returnToChatDashboard(): void {
this.modalService.close();
}
}
import { ModalController } from '@ionic/angular';
import { Injectable } from '@angular/core';
import { ProfileComponent } from '../../components/profile/profile.component';
import { ChatComponent } from '../../components/chat/chat.component';
import { UserData } from '../../interfaces/UserData/userData.interface';
@Injectable({
providedIn: 'root',
})
export class ModalService {
private modal: ModalController;
public constructor(modal: ModalController) {
this.modal = modal;
}
public async openProfileComponent(user: UserData): Promise<void> {
this.modal.dismiss();
const profile = await this.modal.create({
component: ProfileComponent,
componentProps: {
contact: user,
},
});
await profile.present();
}
public async openChatComponent(user: UserData): Promise<void> {
this.modal.dismiss();
const chat = await this.modal.create({
component: ChatComponent,
componentProps: {
contact: user,
},
});
await chat.present();
}
public close(): void {
this.modal.dismiss();
}
}
import { Component } from '@angular/core';
import { ModalService } from '../../componentServices/modal/modal.service';
@Component({
selector: 'app-profile',
templateUrl: './profile.component.html',
styleUrls: ['./profile.component.scss'],
})
export class ProfileComponent {
private modalService: ModalService;
public constructor(modalService: ModalService) {
this.modalService = modalService;
}
public async openChat(): Promise<void> {
this.modalService.openChatComponent(this.contact);
}
public returnToHome(): void {
this.modalService.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment