Skip to content

Instantly share code, notes, and snippets.

@dherges
Last active June 19, 2017 12:09
Show Gist options
  • Select an option

  • Save dherges/dc975b8e097dd4b04f94c9253b4f0f9d to your computer and use it in GitHub Desktop.

Select an option

Save dherges/dc975b8e097dd4b04f94c9253b4f0f9d to your computer and use it in GitHub Desktop.
Angular Testing Snippets: Component (1)
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