Created
November 7, 2019 16:37
-
-
Save ctfrancia/5ce346b3ee228eb1d75b3306f701c71d to your computer and use it in GitHub Desktop.
Triangle of Circular dependency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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