-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83345f9
commit 637a6c9
Showing
6 changed files
with
95 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,55 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { | ||
AfterViewInit, | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
ContentChild, | ||
TemplateRef | ||
} from '@angular/core'; | ||
import { PcSimulatorComponent } from '../simulators/pc-simulator/pc-simulator.component'; | ||
import { Engine, Screen, ScreenType } from '@/app/core/models'; | ||
import { MobileSimulatorComponent } from '@/app/components/simulators/mobile-simulator/mobile-simulator.component'; | ||
import { NgTemplateOutlet } from '@angular/common'; | ||
import { ResponsiveService } from '@/app/services/responsive.service'; | ||
|
||
@Component({ | ||
selector: 'app-simulator', | ||
template: ` | ||
@if (screen.type === ScreenType.PC) { | ||
<app-pc-simulator> | ||
<ng-content></ng-content> | ||
<ng-container *ngTemplateOutlet="template"></ng-container> | ||
</app-pc-simulator> | ||
} @else if (screen.type === ScreenType.Mobile) { | ||
<!-- <app-mobile-simulator>--> | ||
<!-- <ng-content></ng-content>--> | ||
<!-- </app-mobile-simulator>--> | ||
<app-mobile-simulator> | ||
<ng-container *ngTemplateOutlet="template"></ng-container> | ||
</app-mobile-simulator> | ||
} @else { | ||
<!-- <app-pc-simulator>--> | ||
<!-- <ng-content></ng-content>--> | ||
<!-- </app-pc-simulator>--> | ||
<app-pc-simulator> | ||
<ng-container *ngTemplateOutlet="template"></ng-container> | ||
</app-pc-simulator> | ||
} | ||
`, | ||
styles: [``], | ||
standalone: true, | ||
imports: [PcSimulatorComponent, MobileSimulatorComponent], | ||
imports: [PcSimulatorComponent, MobileSimulatorComponent, NgTemplateOutlet], | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class SimulatorComponent { | ||
export class SimulatorComponent implements AfterViewInit { | ||
@ContentChild(TemplateRef) template: TemplateRef<any>; | ||
|
||
screen: Screen; | ||
constructor(private designer: Engine) { | ||
constructor( | ||
private designer: Engine, | ||
private responsiveService: ResponsiveService, | ||
private cdr: ChangeDetectorRef | ||
) { | ||
this.screen = this.designer.screen; | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
console.log('template>>>', this.template); | ||
this.responsiveService.subscribe(() => this.cdr.detectChanges()); | ||
} | ||
|
||
protected readonly ScreenType = ScreenType; | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ResponsiveService { | ||
pageDetection$ = new Subject<boolean>(); | ||
|
||
change() { | ||
this.pageDetection$.next(true); | ||
} | ||
|
||
subscribe(callback: () => void) { | ||
this.pageDetection$.subscribe(v => callback()); | ||
} | ||
} |