<commit_before>import {Directive, ElementRef, Input} from '@angular/core'
import {NgControl} from '@angular/forms'
import createTextMaskInputElement from '../../core/src/createTextMaskInputElement'

@Directive({
  selector: 'input[textMask]',
  host: {
    '(input)': 'onInput()'
  }
})
export default class MaskedInputDirective {
  private inputElement:HTMLInputElement
  public control: any

  @Input('textMask') textMaskConfig = {
    mask: '',
    guide: true,
    placeholderChar: '_',
    pipe: undefined,
    keepCharPositions: false,
    onReject: undefined,
    onAccept: undefined
  }

  constructor(inputElement: ElementRef, private ngControl: NgControl) {
    this.inputElement = inputElement.nativeElement
  }

  ngOnInit() {
    const {placeholderChar} = this.textMaskConfig

    this.control = createTextMaskInputElement(Object.assign({
      inputElement: this.inputElement,
      placeholderChar,
    }, this.textMaskConfig))

    this.control.update()
  }

  onInput() {
    this.control.update()
    this.ngControl.viewToModelUpdate(this.inputElement.value)
  }
}

export {MaskedInputDirective as Directive}
<commit_msg>Angular 2: mask initial value (#110)<commit_after>import {Directive, ElementRef, Input} from '@angular/core'
import {NgControl} from '@angular/forms'
import createTextMaskInputElement from '../../core/src/createTextMaskInputElement'

@Directive({
  selector: 'input[textMask]',
  host: {
    '(input)': 'onInput()'
  }
})
export default class MaskedInputDirective {
  private inputElement:HTMLInputElement;
  public control: any;

  @Input('textMask') textMaskConfig = {
    mask: '',
    guide: true,
    placeholderChar: '_',
    pipe: undefined,
    keepCharPositions: false,
    onReject: undefined,
    onAccept: undefined
  };

  constructor(inputElement: ElementRef, private ngControl: NgControl) {
    this.inputElement = inputElement.nativeElement
  }

  ngOnInit() {
    const {placeholderChar} = this.textMaskConfig;
    this.control = createTextMaskInputElement(Object.assign({
      inputElement: this.inputElement,
      placeholderChar,
    }, this.textMaskConfig));

    setTimeout(() => this.onInput());
  }

  onInput() {
    this.control.update();
    this.ngControl.viewToModelUpdate(this.inputElement.value);
  }
}

export {MaskedInputDirective as Directive}

{'fraction_non_alphanumeric': 0.12117291936179388, 'fraction_numerical': 0.0017248814144027599, 'mean_word_length': 4.225225225225225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5503101', 'n_tokens_mistral': 708, 'n_tokens_neox': 692, 'n_words': 142}