Guest User

Untitled

a guest
Mar 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import { Component, OnInit, Output, EventEmitter } from '@angular/core';
  2. import { FormGroup, FormControl, AbstractControl } from '@angular/forms';
  3.  
  4. @Component({
  5. selector: 'ngx-fizz-buzz',
  6. templateUrl: './ngx-fizz-buzz.component.html',
  7. styleUrls: ['./ngx-fizz-buzz.component.css']
  8. })
  9. export class NgxFizzBuzzComponent implements OnInit {
  10. @Output() said = new EventEmitter<string>();
  11.  
  12. fg: FormGroup;
  13.  
  14. constructor() {}
  15.  
  16. ngOnInit() {
  17. this.fg = new FormGroup({
  18. count: new FormControl()
  19. });
  20. }
  21.  
  22. get count(): AbstractControl {
  23. return this.fg.get('count');
  24. }
  25.  
  26. say() {
  27. if (this.count.value) {
  28. let result = this.count.value;
  29.  
  30. if (Number(this.count.value) % 3 === 0) {
  31. result = 'Fizz';
  32. } else if (Number(this.count.value) % 5 === 0) {
  33. result = 'Buzz';
  34. }
  35.  
  36. this.said.emit(result);
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment