<commit_before>import { Component, Input, Output, ElementRef } from '@angular/core';
import * as Tether from 'tether';

@Component({
  selector: 'vcl-tether',
  templateUrl: 'tether.component.html'
})
export class TetherComponent {

  id: string;

  @Input()
  target: string;

  @Input()
  class: string;

  @Input()
  zIndex: number;

  @Input()
  targetAttachment: string;

  @Input()
  attachment: string;

  constructor(private myElement: ElementRef) {
    this.id = 'tetherId' + Math.floor(Math.random()*10000);
  }

  ngAfterViewInit() {
    try {
      new Tether({
        element: '#' + this.id,
        target: this.target,
        attachment: this.attachment,
        targetAttachment: this.targetAttachment
      });
    } catch (ex) {
      console.log(ex);
    }
  }
}
<commit_msg>Destroy tether instance when view is destroyed. Closes #1.<commit_after>import { Observable } from 'rxjs/Observable';
import { Component, Input, Output, ElementRef, EventEmitter } from '@angular/core';
import * as Tether from 'tether';

let tetherID = 10000;

@Component({
  selector: 'vcl-tether',
  templateUrl: 'tether.component.html'
})
export class TetherComponent {

  id: string;

  @Input()
  target: string;

  @Input()
  class: string;

  @Input()
  zIndex: number;

  @Input()
  targetAttachment: string;

  @Input()
  attachment: string;

  tether: Tether;

  _error = new EventEmitter<any>();
  @Output()
  get error(): Observable<any> {
    return this._error.asObservable();
  }

  constructor(private myElement: ElementRef) {
    this.id = 'vcl-tetherId' + tetherID++;
  }

  ngAfterViewInit() {
    try {
      this.tether = new Tether({
        element: '#' + this.id,
        target: this.target,
        attachment: this.attachment,
        targetAttachment: this.targetAttachment
      });
    } catch (ex) {
      this._error.emit(ex);
    }
  }

  ngOnDestroy() {
    try {
      this.tether && this.tether.destroy();
    } catch (ex) { }
  }
}

{'fraction_non_alphanumeric': 0.1415478615071283, 'fraction_numerical': 0.00560081466395112, 'mean_word_length': 3.010204081632653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1447119', 'n_tokens_mistral': 668, 'n_tokens_neox': 647, 'n_words': 150}