Created
June 14, 2018 17:41
-
-
Save rayonhunte/dbc7af0fcff0c34f3ff02fe6e2da6674 to your computer and use it in GitHub Desktop.
angular binding assessment
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
<div class="container"> | |
<div class="row"> | |
<div class="col-xs-12"> | |
<h3>Bind it!</h3> | |
<div> | |
<app-game-control (addNumber)="showCount($event)"></app-game-control> | |
<div class="row"> | |
<div class="col-xs-6"> | |
<app-even *ngFor="let number of numberCount" [evenNumber]="number"></app-even> | |
</div> | |
<div class="col-xs-6"> | |
<app-odd *ngFor="let number of numberCount" [oddNumber]="number"></app-odd> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> |
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'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
numberCount = []; | |
showCount(count: {count: number}) { | |
console.log(count.count); | |
this.numberCount.push(count.count); | |
} | |
} |
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
<p *ngIf="evenNumber % 2 === 0"> | |
Even Number {{evenNumber}} | |
</p> | |
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, OnInit, Input } from '@angular/core'; | |
@Component({ | |
selector: 'app-even', | |
templateUrl: './even.component.html', | |
styleUrls: ['./even.component.css'] | |
}) | |
export class EvenComponent implements OnInit { | |
@Input() evenNumber: number; | |
constructor() { } | |
ngOnInit() { | |
} | |
} |
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
<div class="content"> | |
<button class="btn btn-primary btn-space" | |
(click)="OnStart()"> | |
Start | |
</button> | |
<button class="btn btn-danger btn-space" | |
(click)="OnStop()"> | |
Stop | |
</button> | |
</div> |
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, OnInit, EventEmitter, Output } from '@angular/core'; | |
@Component({ | |
selector: 'app-game-control', | |
templateUrl: './game-control.component.html', | |
styleUrls: ['./game-control.component.css'] | |
}) | |
export class GameControlComponent implements OnInit { | |
myTimer; | |
count = 0; | |
@Output() addNumber = new EventEmitter <{count: number}>(); | |
constructor() { } | |
ngOnInit() { | |
} | |
OnStart() { | |
this.myTimer = setInterval(() => { | |
this.addNumber.emit({count: this.count++}); | |
}, 1000); | |
} | |
OnStop() { | |
clearInterval(this.myTimer); | |
} | |
} |
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
<p *ngIf="oddNumber % 2 !== 0"> | |
Odd Numbers {{oddNumber}} | |
</p> |
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, OnInit, Input } from '@angular/core'; | |
@Component({ | |
selector: 'app-odd', | |
templateUrl: './odd.component.html', | |
styleUrls: ['./odd.component.css'] | |
}) | |
export class OddComponent implements OnInit { | |
@Input() oddNumber: number; | |
constructor() { } | |
ngOnInit() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment