Last active
June 19, 2017 12:09
-
-
Save dherges/dc975b8e097dd4b04f94c9253b4f0f9d to your computer and use it in GitHub Desktop.
Angular Testing Snippets: Component (1)
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
| import { Component, EventEmitter, Input, Output } from '@angular/core'; | |
| /** | |
| * A very dumb replacement for `<input type="number">`. | |
| * | |
| * Usage: `<my-number [value]="99" (onValueChanges)="changed($event)></my-number> | |
| */ | |
| @Component({ | |
| selector: 'my-number', | |
| template: '<input type="text" [value]="value" (change)="onChange($event.target.value)">' | |
| }) | |
| export class NumberComponent { | |
| /** Sets the current value of the input. */ | |
| @Input() | |
| public value: number; | |
| /** Notifies when the value of the input changes. */ | |
| @Output() | |
| public onValueChanges: EventEmitter<number> = new EventEmitter<number>(); | |
| public onChange(value: any) { | |
| const numValue: number = Number.parseInt(value); | |
| this.onValueChanges.emit(numValue); | |
| this.value = numValue; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment