This file contains hidden or 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
| export class GameCardComponent implements OnInit { | |
| data: CardData = { | |
| imageId: "pDGNBK9A0sk", | |
| state: "default" | |
| }; | |
| cardClicked() { | |
| if (this.data.state === "default") { | |
| this.data.state = "flipped"; |
This file contains hidden or 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
| export class GameCardComponent implements OnInit { | |
| @Input() data: CardData; | |
| @Output() cardClicked = new EventEmitter(); | |
| constructor() { } | |
| ngOnInit(): void { | |
| } |
This file contains hidden or 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
| <div class="card" (click)="cardClicked.emit()" [@cardFlip]="data.state"> | |
| <div class="face back"> | |
| <img src="assets/card-back.jpg"> | |
| </div> | |
| <div class="face front"> | |
| <img [src]="'https://source.unsplash.com/' + data.imageId + '/200x300'"> | |
| </div> | |
| </div> |
This file contains hidden or 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
| ngOnInit(): void { | |
| this.setupCards(); | |
| } | |
| setupCards(): void { | |
| this.cards = []; | |
| this.cardImages.forEach((image) => { | |
| const cardData: CardData = { | |
| imageId: image, |
This file contains hidden or 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
| <mat-toolbar color="primary" class="text-center"> | |
| Card Memory Game | |
| </mat-toolbar> | |
| <div class="p-16"> | |
| <p class="text-center">Tap on a card to flip it. You can only flip a maximum of two cards at a time. A match will | |
| remove | |
| those cards!</p> | |
| <div class="grid p-16"> | |
| <app-game-card *ngFor="let c of cards; let idx=index" [data]="c" (cardClicked)="cardClicked(idx)"> |
This file contains hidden or 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
| cardClicked(index: number): void { | |
| const cardInfo = this.cards[index]; | |
| if (cardInfo.state === 'default' && this.flippedCards.length < 2) | |
| { | |
| cardInfo.state = 'flipped'; | |
| this.flippedCards.push(cardInfo); | |
| if (this.flippedCards.length === 2) { | |
| this.checkForCardMatch(); |
This file contains hidden or 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
| checkForCardMatch(): void { | |
| setTimeout(() => { | |
| const cardOne = this.flippedCards[0]; | |
| const cardTwo = this.flippedCards[1]; | |
| const nextState = cardOne.imageId === cardTwo.imageId ? 'matched' : 'default'; | |
| cardOne.state = cardTwo.state = nextState; | |
| this.flippedCards = []; | |
This file contains hidden or 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
| <mat-toolbar color="primary"> | |
| Material Tabs with Lazy Loaded Routes | |
| </mat-toolbar> | |
| <nav mat-tab-nav-bar> | |
| <a mat-tab-link *ngFor="let tabItem of tabs"> | |
| <mat-icon class="mr-8">{{tabItem.icon}}</mat-icon> | |
| {{tabItem.label}} | |
| </a> | |
| </nav> |
This file contains hidden or 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
| @NgModule({ | |
| declarations: [SectionOneComponent], | |
| imports: [ | |
| CommonModule, | |
| RouterModule.forChild( | |
| [{ path: '', component: SectionOneComponent }] | |
| ), | |
| MatCardModule, | |
| MatButtonModule, | |
| ], |
This file contains hidden or 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
| const routes: Routes = [ | |
| { | |
| path: '', | |
| pathMatch: 'full', | |
| redirectTo: 'one', | |
| }, | |
| { | |
| path: 'one', | |
| loadChildren: () => | |
| import('./section-one/section-one.module').then( |