import { Component,Input, Injectable, ElmentRef, ViewChild, ApplicationRef, ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FormGroup, FormControl } from '@angular/forms';
import { Observable, of, timer } from 'rxjs';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { Multiselect } from './multiselect.component';

@Component({
    selector: 'my-app',
    templateUrl: 'templates/app.html',
    changeDetection: ChangeDetectionStrategy.OnPush,
    host: { '(document:click)': 'hostClick($event)' },
})

export class AppComponent implements OnInit {
    public items: Observable<Array<any>>;
    public _selectedItems: Array<any> = [];
    public watchedItems: Array<any>;
    private _items: Array<any>;
    private _lipsum: any;
    
    @ViewChild('start') start: any;
    @ViewChild('end') end: any;

    @ViewChild('startContainer') startContainer: ElementRef;
    @ViewChild('endContainer') endContainer: ElementRef;
  
    hostClick(event) {
      let startIsOpen: boolean = this.start.isOpen();
      let endIsOpen: boolean = this.end.isOpen();

      if (startIsOpen) {
          if (this.startContainer && this.startContainer.nativeElement && !this.startContainer.nativeElement.contains(event.target)) {                
              console.log("Not in startDate container - closing.");
              this.start.close();
          }
      }

      if (endIsOpen) {
          if (this.endContainer && this.endContainer.nativeElement && !this.endContainer.nativeElement.contains(event.target)) {
              console.log("Not in endDate container - closing.");
              this.end.close();
          }
      }
  }    
    constructor(private changeRef: ChangeDetectorRef, private appRef: ApplicationRef) {
        declare var LoremIpsum: any;
        this._lipsum = new LoremIpsum();
        this._items = [];
        this.items = of(this._items);
        this.items.subscribe(res => { console.log("Items changed"); this.watchedItems = res; });
    }
    
    get selectedItems(): any {
        return this._selectedItems;
    };
    
    createItems() {
      this._items.length = 0;
      var max: int = 20;
      var min: int = 10;
      var numItems: int = Math.floor(Math.random() * (max - min + 1)) + min; 
      console.log("Adding " + numItems.toString() + " items");
      max = 6;
      min = 3;
      var i: int;
      for (i =0; i < numItems; i++) {
        var numWords: int = Math.floor(Math.random() * (max - min + 1)) + min;
        var label: string = this._lipsum.generate(numWords); 
        this._items.push({ label: label, value: i.toString()});
          console.log(label);
      }
      
      // Randomly choose a few items
      this.randomSelect();
    }
    
    randomSelect() {
      var numItems: int = this.getRandomInt(0, this._items.length) + 1;
      var min: int = 0;
      var max: int = this._items.length - 1;
      var toSelectIndexes: Array<int> = [];
      for (var j: int = 0; j < this.getRandomInt(1, numItems); j++) {
          var randIndex: int = this.getRandomInt(min, max);
          var arrIndex = toSelectIndexes.indexOf(randIndex);
          if (arrIndex == -1) {
              toSelectIndexes.push(randIndex);
              this._selectedItems.push(this._items[randIndex]);
          }
      }
    }
    
    getRandomInt(min: int, max: int) {
      return Math.floor(Math.random() * (max - min + 1) + min);
    }
        
    ngOnInit() {
      this.createItems();
      let myTimer = timer(20000,20000);
      myTimer.subscribe(t=> {
        //this.createItems();
      });
    }

    onChange(event) { }
}

@Pipe({
    name: 'equal',
    pure: false
})

export class EqualPipe implements PipeTransform {
    transform(items: any, filter: any): any {
      if (filter && Array.isArray(items)) {
          let filterKeys = Object.keys(filter);
          return items.filter(item =>
              filterKeys.reduce((memo, keyName) => {
                  console.log("Comparing");
                  return item[keyName] === filter[keyName];}, true)
                  );
      } else {
          return items;
      }
    }
}

import { Component, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { JsonpModule } from '@angular/http';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppComponent, EqualPipe } from './app.component';
import { LoremIpsumService } from './services/loremIpsum.service';

@NgModule({
  imports: [BrowserModule, FormsModule, ReactiveFormsModule, JsonpModule, NgbModule.forRoot()], 
  declarations: [ AppComponent, EqualPipe ],
  providers: [ LoremIpsumService ],
  bootstrap:    [ AppComponent ]
})

export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
import { Injectable } from '@angular/core';

@Injectable()
export class LoremIpsumService {
    private WORDS_PER_SENTENCE_AVG: number = 24.260;
    private WORDS_PER_SENTENCE_STD: number = 5.080;

    private WORDS: Array<string> = [
        'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
        'adipiscing', 'elit', 'curabitur', 'vel', 'hendrerit', 'libero',
        'eleifend', 'blandit', 'nunc', 'ornare', 'odio', 'ut',
        'orci', 'gravida', 'imperdiet', 'nullam', 'purus', 'lacinia',
        'a', 'pretium', 'quis', 'congue', 'praesent', 'sagittis',
        'laoreet', 'auctor', 'mauris', 'non', 'velit', 'eros',
        'dictum', 'proin', 'accumsan', 'sapien', 'nec', 'massa',
        'volutpat', 'venenatis', 'sed', 'eu', 'molestie', 'lacus',
        'quisque', 'porttitor', 'ligula', 'dui', 'mollis', 'tempus',
        'at', 'magna', 'vestibulum', 'turpis', 'ac', 'diam',
        'tincidunt', 'id', 'condimentum', 'enim', 'sodales', 'in',
        'hac', 'habitasse', 'platea', 'dictumst', 'aenean', 'neque',
        'fusce', 'augue', 'leo', 'eget', 'semper', 'mattis',
        'tortor', 'scelerisque', 'nulla', 'interdum', 'tellus', 'malesuada',
        'rhoncus', 'porta', 'sem', 'aliquet', 'et', 'nam',
        'suspendisse', 'potenti', 'vivamus', 'luctus', 'fringilla', 'erat',
        'donec', 'justo', 'vehicula', 'ultricies', 'varius', 'ante',
        'primis', 'faucibus', 'ultrices', 'posuere', 'cubilia', 'curae',
        'etiam', 'cursus', 'aliquam', 'quam', 'dapibus', 'nisl',
        'feugiat', 'egestas', 'class', 'aptent', 'taciti', 'sociosqu',
        'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra',
        'inceptos', 'himenaeos', 'phasellus', 'nibh', 'pulvinar', 'vitae',
        'urna', 'iaculis', 'lobortis', 'nisi', 'viverra', 'arcu',
        'morbi', 'pellentesque', 'metus', 'commodo', 'ut', 'facilisis',
        'felis', 'tristique', 'ullamcorper', 'placerat', 'aenean', 'convallis',
        'sollicitudin', 'integer', 'rutrum', 'duis', 'est', 'etiam',
        'bibendum', 'donec', 'pharetra', 'vulputate', 'maecenas', 'mi',
        'fermentum', 'consequat', 'suscipit', 'aliquam', 'habitant', 'senectus',
        'netus', 'fames', 'quisque', 'euismod', 'curabitur', 'lectus',
        'elementum', 'tempor', 'risus', 'cras'
    ];

    constructor() {
    }

    public singleWord(): string {
        var position = Math.floor(Math.random() * this.WORDS.length);
        var word = this.WORDS[position];
        return word.charAt(0).toUpperCase() + word.slice(1);
    };

    public generate(num_words: number) {
        var words, ii, position, word, current, sentences, sentence_length, sentence;

        /**
         * @default 100
         */
        num_words = num_words || 100;

        words = [this.WORDS[0], this.WORDS[1]];
        num_words -= 2;

        for (ii = 0; ii < num_words; ii++) {
            position = Math.floor(Math.random() * this.WORDS.length);
            word = this.WORDS[position];

            if (ii > 0 && words[ii - 1] === word) {
                ii -= 1;

            } else {
                words[ii] = word;
            }
        }

        sentences = [];
        current = 0;

        while (num_words > 0) {
            sentence_length = this.getRandomSentenceLength();

            if (num_words - sentence_length < 4) {
                sentence_length = num_words;
            }

            num_words -= sentence_length;

            sentence = [];

            for (ii = current; ii < (current + sentence_length); ii++) {
                sentence.push(words[ii]);
            }

            sentence = this.punctuate(sentence);
            current += sentence_length;
            sentences.push(sentence.join(' '));
        }

        return sentences.join(' ');
    };

    public punctuate(sentence: any) {
        var word_length, num_commas, ii, position;

        word_length = sentence.length;

        /* End the sentence with a period. */
        sentence[word_length - 1] += '.';

        if (word_length < 4) {
            return sentence;
        }

        num_commas = this.getRandomCommaCount(word_length);

        for (ii = 0; ii <= num_commas; ii++) {
            position = Math.round(ii * word_length / (num_commas + 1));

            if (position < (word_length - 1) && position > 0) {
                /* Add the comma. */
                sentence[position] += ',';
            }
        }

        /* Capitalize the first word in the sentence. */
        sentence[0] = sentence[0].charAt(0).toUpperCase() + sentence[0].slice(1);

        return sentence;
    }

    public getRandomCommaCount(word_length: number) {
        var base, average, standard_deviation;

        /* Arbitrary. */
        base = 6;

        average = Math.log(word_length) / Math.log(base);
        standard_deviation = average / base;

        return Math.round(this.gaussMS(average, standard_deviation));
    }

    public getRandomSentenceLength() {
        return Math.round(
            this.gaussMS(
                this.WORDS_PER_SENTENCE_AVG,
                this.WORDS_PER_SENTENCE_STD
            )
        );
    }

    private gauss() {
        return (Math.random() * 2 - 1) +
            (Math.random() * 2 - 1) +
            (Math.random() * 2 - 1);
    }

    private gaussMS(mean: number, standard_deviation: number) {
        return Math.round(this.gauss() * standard_deviation + mean);
    }
}
/* Master Styles */

h1 {
  color: #369;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 250%;
}

h2,
h3 {
  color: #444;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: lighter;
}

body {
  margin: 2em;
}

body,
input[text],
button {
  color: #888;
  font-family: Cambria, Georgia;
}

a {
  cursor: pointer;
  cursor: hand;
}

button {
  font-family: Arial;
  background-color: #eee;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  cursor: hand;
}

button:hover {
  background-color: #cfd8dc;
}

button:disabled {
  background-color: #eee;
  color: #aaa;
  cursor: auto;
}


/* Navigation link styles */

nav a {
  padding: 5px 10px;
  text-decoration: none;
  margin-top: 10px;
  display: inline-block;
  background-color: #eee;
  border-radius: 4px;
}

nav a:visited,
a:link {
  color: #607D8B;
}

nav a:hover {
  color: #039be5;
  background-color: #CFD8DC;
}

nav a.active {
  color: #039be5;
}


/* items class */

.items {
  margin: 0 0 2em 0;
  list-style-type: none;
  padding: 0;
  width: 24em;
}

.items li {
  cursor: pointer;
  position: relative;
  left: 0;
  background-color: #EEE;
  margin: .5em;
  padding: .3em 0;
  height: 1.6em;
  border-radius: 4px;
}

.items li:hover {
  color: #607D8B;
  background-color: #DDD;
  left: .1em;
}

.items li.selected:hover {
  background-color: #BBD8DC;
  color: white;
}

.items .text {
  position: relative;
  top: -3px;
}

.items {
  margin: 0 0 2em 0;
  list-style-type: none;
  padding: 0;
  width: 24em;
}

.items li {
  cursor: pointer;
  position: relative;
  left: 0;
  background-color: #EEE;
  margin: .5em;
  padding: .3em 0;
  height: 1.6em;
  border-radius: 4px;
}

.items li:hover {
  color: #607D8B;
  background-color: #DDD;
  left: .1em;
}

.items li.selected {
  background-color: #CFD8DC;
  color: white;
}

.items li.selected:hover {
  background-color: #BBD8DC;
}

.items .text {
  position: relative;
  top: -3px;
}

.items .badge {
  display: inline-block;
  font-size: small;
  color: white;
  padding: 0.8em 0.7em 0 0.7em;
  background-color: #607D8B;
  line-height: 1em;
  position: relative;
  left: -1px;
  top: -4px;
  height: 1.8em;
  margin-right: .8em;
  border-radius: 4px 0 0 4px;
}


/* everywhere else */

* {
  font-family: Arial, Helvetica, sans-serif;
}

multiselect {
  display: block;
}

multiselect > .btn-group {
  min-width: 180px;
}

multiselect .dropdown-toggle:after {
  content: none;
}

multiselect .btn {
  width: 100%;
  background-color: #FFF;
}
multiselect .btn.has-error {
  border: 1px solid #a94442 !important;
  color: #db524b;
}
multiselect .dropdown-menu {
  max-height: 300px;
  min-width: 200px;
  overflow-y: auto;
}
multiselect .dropdown-menu .filter > input {
  width: 99%;
}
multiselect .dropdown-menu .filter .clear-filter  {
  cursor: pointer;
  pointer-events: all;
      position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    display: block;
    width: 34px;
    height: 34px;
    line-height: 34px;
    text-align: center;
}
multiselect .dropdown-menu {
  /* width: 100%; */
  box-sizing: border-box;
  padding: 2px;
}
multiselect > .btn-group > button {
  padding-right: 20px;
}
multiselect > .btn-group > button > .caret {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid black;
  right: 5px;
  top: 45%;
  position: absolute;
}
multiselect .dropdown-menu > li > a {
  padding: 3px 10px;
  cursor: pointer;
}
multiselect .dropdown-menu > li > a i {
  margin-right: 4px;
}
.glyphicon-none:before {
  content: "\e013";
  color: transparent !important;
}
<!DOCTYPE html>
<html>
  <head>
    <title>Angular Datepicker</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
    <link rel="stylesheet" href="styles.css" />  
    <!-- 1. Load libraries -->
    <script src="lorem-ipsum.js"></script>    
     <!-- Polyfill(s) for older browsers -->
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://unpkg.com/zone.js@0.8.26/dist/zone.js?main=browser"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.12"></script>
    <script src="https://unpkg.com/systemjs@0.19.47/dist/system.src.js"></script>

    <!-- 2. Configure SystemJS -->
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
  </head>

  <!-- 3. Display the application -->
  <body>
    <my-app>Loading...</my-app>
  </body>
</html>
### This is a simple base demo plunker

This is a demo/plunker for Angular Boostrap components
(function (global) {
  var angularVersion = '@7.1.4';
  
  System.config({
    // DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
    transpiler: 'ts',
    typescriptOptions: {
      // Copy of compiler options in standard tsconfig.json
      "target": "es5",
      "module": "commonjs",
      "moduleResolution": "node",
      "sourceMap": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "lib": ["es2015", "dom"],
      "noImplicitAny": true,
      "suppressImplicitAnyIndexErrors": true
    },
    meta: {
      'typescript': {
        "exports": "ts"
      }
    },
    paths: {
      // paths serve as alias
      'npm:': 'https://unpkg.com/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',
      service: 'serivce',
      
      // angular bundles
      '@angular/core': 'npm:@angular/core' + angularVersion + '/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common' + angularVersion + '/bundles/common.umd.js',
      '@angular/common/http': 'npm:@angular/common' + angularVersion + '/bundles/common-http.umd.js',
      '@angular/compiler': 'npm:@angular/compiler' + angularVersion + '/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser.umd.js',
      '@angular/platform-browser/animations': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser-animations.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic' + angularVersion + '/bundles/platform-browser-dynamic.umd.js',
      '@angular/platform-webworker': 'npm:@angular/platform-webworker' + angularVersion + '/bundles/platform-webworker.umd.js',
      '@angular/platform-webworker-dynamic': 'npm:@angular/platform-webworker-dynamic' + angularVersion + '/bundles/platform-webworker-dynamic.umd.js',   
      '@angular/http': 'npm:@angular/http' + angularVersion + '/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router' + angularVersion + '/bundles/router.umd.js',
      '@angular/router/upgrade': 'npm:@angular/router' + angularVersion + '/bundles/router-upgrade.umd.js',
      '@angular/forms': 'npm:@angular/forms' + angularVersion + '/bundles/forms.umd.js',
      '@angular/upgrade': 'npm:@angular/upgrade' + angularVersion + '/bundles/upgrade.umd.js',
      '@angular/upgrade/static': 'npm:@angular/upgrade' + angularVersion + '/bundles/upgrade-static.umd.js',
      '@angular/animations': 'npm:@angular/animations' + angularVersion + '/bundles/animations.umd.js',
      '@angular/animations/browser': 'npm:@angular/animations' + angularVersion + '/bundles/animations-browser.umd.js',
      
      // other libraries
      'rxjs':                      'npm:rxjs@6.3.3',
      'rxjs-compat':               'npm:rxjs-compat@6.3.3',
      'ts':                        'npm:plugin-typescript@8.0.0/lib/plugin.js',
      'tslib':                     'npm:tslib@1.9.3',
      'typescript':                'npm:typescript@3.2.2/lib/typescript.js',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api@0.8.0/bundles/in-memory-web-api.umd.js',
      '@ng-bootstrap/ng-bootstrap': 'npm:@ng-bootstrap/ng-bootstrap@4.0.1/bundles/ng-bootstrap.umd.js'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.ts',
        defaultExtension: 'ts',
        meta: {
          './*.ts': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      service: {
        defaultExtension: 'ts'
      },
      'rxjs': {main: 'index.js', defaultExtension: 'js' },
      'rxjs/ajax': {main: 'index.js', defaultExtension: 'js' },
      'rxjs/operators': {main: 'index.js', defaultExtension: 'js' },
      'rxjs/testing': {main: 'index.js', defaultExtension: 'js' },
      'rxjs/webSocket': {main: 'index.js', defaultExtension: 'js' }
      }
  });

})(this);
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "types": []
  },
  "exclude": [
    "node_modules/*",
    "**/*-aot.ts"
  ]
}
<div class="container-fluid">
  <hr>
  <p>
    This demo plnkr of an Angular <strong>Datepicker</strong> project: Angular powered Bootstrap. Visit <a href="https://long2know.com/" target="_blank">https://long2know.com</a> for more demos and discussion..
  </p>
  <hr>
  <h2>Default pickers</h2>
  <div class="row container">
    <form name="searchForm" class="form-inline" role="form">
      <div class="form-group mb-2 mr-sm-2 mb-sm-0">
        <div class="input-group">
          <input class="form-control" placeholder="Picker 1" name="d1" [(ngModel)]="startDate" ngbDatepicker #d1="ngbDatepicker">
          <button class="input-group-addon btn btn-default" type="button" (click)="d1.toggle()">
            <i class="fa fa-calendar" aria-hidden="true"></i>
          </button>
        </div>
      </div>

      <div class="form-group mb-2 mr-sm-2 mb-sm-0">
        <div class="input-group">
          <input class="form-control" placeholder="Picker 2" name="d2" [(ngModel)]="model" ngbDatepicker #d2="ngbDatepicker">
          <button class="input-group-addon btn btn-default" type="button" (click)="d2.toggle()">
             <i class="fa fa-calendar" aria-hidden="true"></i>
          </button>
        </div>
      </div>
    </form>
  </div>
  <hr>
  
  <h2>Managed pickers</h2>
  <div class="row container">
    <form name="searchForm" class="form-inline" role="form">

    <div class="form-group mb-2 mr-sm-2 mb-sm-0" #startContainer>
      <div class="input-group">
        <input class="form-control" placeholder="Start date" name="startDate" [(ngModel)]="startDate" ngbDatepicker #start="ngbDatepicker">
        <button class="input-group-addon btn btn-default" type="button" (click)="start.toggle()">
          <i class="fa fa-calendar" aria-hidden="true"></i>
        </button>
      </div>
    </div>

      <div class="form-group mb-2 mr-sm-2 mb-sm-0" #endContainer>
        <div class="input-group">
          <input class="form-control" placeholder="End date" name="endDate" [(ngModel)]="model" ngbDatepicker #end="ngbDatepicker">
          <button class="input-group-addon btn btn-default" type="button" (click)="end.toggle()">
            <i class="fa fa-calendar" aria-hidden="true"></i>
          </button>
        </div>
      </div>
    </form>
  </div>
</div>
<div class="btn-group">
  <button type="button" class="btn btn-secondary dropdown-toggle" (click)="toggleSelect()">
    <span class="pull-left" [innerHtml]="header"></span>
    <span class="caret pull-right"></span>
  </button>
  <ul class="dropdown-menu multi-select-popup" [ngStyle]="{display:isOpen ? 'block' : 'none'}" style="display:block;">
    <li *ngIf="enableFilter" class="filter-container">
      <div class="form-group has-feedback filter">
        <input class="form-control" type="text" [value]="filterText" [placeholder]="filterPlaceholder" [formControl]="filterInput" />
        <span class="clear-filter fa fa-times-circle-o form-control-feedback" (click)="clearFilter()"></span>
      </div>
    </li>
    <li *ngFor="let item of _items | filter:{label:filterText}">
      <a (click)="select(item)" class="dropdown-item">
        <i class="fa fa-fw" [ngClass]="{'fa-check': item.checked, 'glyphicon-none': !item.checked}"></i>
        <span [innerHtml]="item.label"></span>
      </a>
    </li>
  </ul>
</div>

<br/>
<br/>
<br/>
<br/>

<!--
<div class="btn-group" ng-class="{ dropup: dropup, single: !multiple }">
    <button type="button" class="btn btn-default dropdown-toggle" ng-click="toggleSelect()" ng-disabled="disabled" ng-class="{'has-error': !valid()}">
        <span class="pull-left" ng-bind="header"></span>
        <span class="caret pull-right"></span>
    </button>
    <ul class="dropdown-menu multi-select-popup" ng-show="isOpen && !moveInProgress" ng-style="{ true: {top: position.top +'px', left: position.left +'px'}, false: {}}[appendToBody]" style="display: block;" role="listbox" aria-hidden="{{!isOpen}}">
        <li *ngIf="enableFilter" class="filter-container">
            <div class="form-group has-feedback filter">
                <input class="form-control" type="text" ng-model="searchText.label" placeholder="{{ filterPlaceholder }}" />
                <span class="glyphicon glyphicon-remove-circle form-control-feedback" ng-click="clearFilter()"></span>
            </div>
        </li>
        <li ng-show="multiple && (enableCheckAll || enableUncheckAll)">
            <button ng-if="enableCheckAll" type="button" class="btn-link btn-small" ng-click="checkAll()"><i class="icon-ok"></i> {{ checkAllLabel }}</button>
            <button ng-if="enableUncheckAll" type="button" class="btn-link btn-small" ng-click="uncheckAll()"><i class="icon-remove"></i> {{ uncheckAllLabel }}</button>
        </li>
        <li ng-show="maxSelected">
            <small>Selected maximum of </small><small ng-bind="selectLimit"></small>
        </li>
        <li ng-repeat="i in items | filter:searchText">
            <a ng-click="select(i);">
                <i class="glyphicon" ng-class="{'glyphicon-ok': i.checked, 'glyphicon-none': !i.checked}"></i>
                <span ng-bind="i.label"></span>
            </a>
        </li>
    </ul>
</div>

-->
/**
 * @fileOverview Generates "Lorem ipsum" style text.
 * @author rviscomi@gmail.com Rick Viscomi,
 * 		tinsley@tinsology.net Mathew Tinsley
 * @version 1.0
 */

/**
 *	Copyright (c) 2009, Mathew Tinsley (tinsley@tinsology.net)
 *	All rights reserved.
 *
 *	Redistribution and use in source and binary forms, with or without
 *	modification, are permitted provided that the following conditions are met:
 *		* Redistributions of source code must retain the above copyright
 *		  notice, this list of conditions and the following disclaimer.
 *		* Redistributions in binary form must reproduce the above copyright
 *		  notice, this list of conditions and the following disclaimer in the
 *		  documentation and/or other materials provided with the distribution.
 *		* Neither the name of the organization nor the
 *		  names of its contributors may be used to endorse or promote products
 *		  derived from this software without specific prior written permission.
 *
 *	THIS SOFTWARE IS PROVIDED BY MATHEW TINSLEY ''AS IS'' AND ANY
 *	EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *	WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *	DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
 *	DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *	ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * @class Jibborish generator.
 */
var LoremIpsum = function () {
};

/**
 * Average number of words per sentence.
 * @constant {number}
 */
LoremIpsum.WORDS_PER_SENTENCE_AVG = 24.460;

/**
 * Standard deviation of the number of words per sentence.
 * @constant {number}
 */
LoremIpsum.WORDS_PER_SENTENCE_STD = 5.080;

/**
 * List of possible words.
 * @constant {Array.string}
 */
LoremIpsum.WORDS = [
		'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
		'adipiscing', 'elit', 'curabitur', 'vel', 'hendrerit', 'libero',
		'eleifend', 'blandit', 'nunc', 'ornare', 'odio', 'ut',
		'orci', 'gravida', 'imperdiet', 'nullam', 'purus', 'lacinia',
		'a', 'pretium', 'quis', 'congue', 'praesent', 'sagittis', 
		'laoreet', 'auctor', 'mauris', 'non', 'velit', 'eros',
		'dictum', 'proin', 'accumsan', 'sapien', 'nec', 'massa',
		'volutpat', 'venenatis', 'sed', 'eu', 'molestie', 'lacus',
		'quisque', 'porttitor', 'ligula', 'dui', 'mollis', 'tempus',
		'at', 'magna', 'vestibulum', 'turpis', 'ac', 'diam',
		'tincidunt', 'id', 'condimentum', 'enim', 'sodales', 'in',
		'hac', 'habitasse', 'platea', 'dictumst', 'aenean', 'neque',
		'fusce', 'augue', 'leo', 'eget', 'semper', 'mattis', 
		'tortor', 'scelerisque', 'nulla', 'interdum', 'tellus', 'malesuada',
		'rhoncus', 'porta', 'sem', 'aliquet', 'et', 'nam',
		'suspendisse', 'potenti', 'vivamus', 'luctus', 'fringilla', 'erat',
		'donec', 'justo', 'vehicula', 'ultricies', 'varius', 'ante',
		'primis', 'faucibus', 'ultrices', 'posuere', 'cubilia', 'curae',
		'etiam', 'cursus', 'aliquam', 'quam', 'dapibus', 'nisl',
		'feugiat', 'egestas', 'class', 'aptent', 'taciti', 'sociosqu',
		'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra',
		'inceptos', 'himenaeos', 'phasellus', 'nibh', 'pulvinar', 'vitae',
		'urna', 'iaculis', 'lobortis', 'nisi', 'viverra', 'arcu',
		'morbi', 'pellentesque', 'metus', 'commodo', 'ut', 'facilisis',
		'felis', 'tristique', 'ullamcorper', 'placerat', 'aenean', 'convallis',
		'sollicitudin', 'integer', 'rutrum', 'duis', 'est', 'etiam',
		'bibendum', 'donec', 'pharetra', 'vulputate', 'maecenas', 'mi',
		'fermentum', 'consequat', 'suscipit', 'aliquam', 'habitant', 'senectus',
		'netus', 'fames', 'quisque', 'euismod', 'curabitur', 'lectus',
		'elementum', 'tempor', 'risus', 'cras'
];

LoremIpsum.prototype.singleWord = function () {
  var position = Math.floor(Math.random() * LoremIpsum.WORDS.length);
  var word = LoremIpsum.WORDS[position];
  return word.charAt(0).toUpperCase() + word.slice(1);
}

/**
 * Generate "Lorem ipsum" style words.
 * @param num_words {number} Number of words to generate.
 * @return {string} "Lorem ipsum..."
 */
LoremIpsum.prototype.generate = function (num_words) {
	var words, ii, position, word, current, sentences, sentence_length, sentence;
	
	/**
	 * @default 100
	 */
	num_words = num_words || 100;
	
	words = [LoremIpsum.WORDS[0], LoremIpsum.WORDS[1]];
	num_words -= 2;
	
	for (ii = 0; ii < num_words; ii++) {
		position = Math.floor(Math.random() * LoremIpsum.WORDS.length);
		word = LoremIpsum.WORDS[position];
		
		if (ii > 0 && words[ii - 1] === word) {
			ii -= 1;
			
		} else {
			words[ii] = word;
		}
	}
	
	sentences = [];
	current = 0;
	
	while (num_words > 0) {
		sentence_length = this.getRandomSentenceLength();
		
		if (num_words - sentence_length < 4) {
			sentence_length = num_words;
		}
		
		num_words -= sentence_length;
		
		sentence = [];
		
		for (ii = current; ii < (current + sentence_length); ii++) {
			sentence.push(words[ii]);
		}
		
		sentence = this.punctuate(sentence);
		current += sentence_length;
		sentences.push(sentence.join(' '));
	}
	
	return sentences.join(' ');
};

/**
 * Insert commas and periods in the given sentence.
 * @param {Array.string} sentence List of words in the sentence.
 * @return {Array.string} Sentence with punctuation added.
 */
LoremIpsum.prototype.punctuate = function (sentence) {
	var word_length, num_commas, ii, position;
	
	word_length = sentence.length;
	
	/* End the sentence with a period. */
	sentence[word_length - 1] += '.';
	
	if (word_length < 4) {
		return sentence;
	}
	
	num_commas = this.getRandomCommaCount(word_length);
	
	for (ii = 0; ii <= num_commas; ii++) {
		position = Math.round(ii * word_length / (num_commas + 1));
		
		if (position < (word_length - 1) && position > 0) {
			/* Add the comma. */
			sentence[position] += ',';
		}
	}
	
	/* Capitalize the first word in the sentence. */
	sentence[0] = sentence[0].charAt(0).toUpperCase() + sentence[0].slice(1);
	
	return sentence;
};

/**
 * Produces a random number of commas.
 * @param {number} word_length Number of words in the sentence.
 * @return {number} Random number of commas
 */
LoremIpsum.prototype.getRandomCommaCount = function (word_length) {
	var base, average, standard_deviation;
	
	/* Arbitrary. */
	base = 6;
	
	average = Math.log(word_length) / Math.log(base);
	standard_deviation = average / base;
	
	return Math.round(this.gaussMS(average, standard_deviation));
};

/**
 * Produces a random sentence length based on the average word length
 * of an English sentence.
 * @return {number} Random sentence length
 */
LoremIpsum.prototype.getRandomSentenceLength = function () {
	return Math.round(
			this.gaussMS(
					LoremIpsum.WORDS_PER_SENTENCE_AVG,
					LoremIpsum.WORDS_PER_SENTENCE_STD
			)
	);
};

/**
 * Produces a random number.
 * @return {number} Random number
 */
LoremIpsum.prototype.gauss = function () {
	return (Math.random() * 2 - 1) +
			(Math.random() * 2 - 1) +
			(Math.random() * 2 - 1);
};

/**
 * Produces a random number with Gaussian distribution.
 * @param {number} mean
 * @param {number} standard_deviation
 * @return {number} Random number
 */
LoremIpsum.prototype.gaussMS = function (mean, standard_deviation) {
	return Math.round(this.gauss() * standard_deviation + mean);
};
this.sharedData.tabSet.select(id);
console.log(this.sharedData.tabSet);
Observable.create(observer => {
    setTimeout(() => {
        this.sharedData.tabSet.select(id)
        observer.complete();
        console.log("Observer complete");
    }, 1);
})
.subscribe(
  result => {
      this.sharedData.tabSet.select(id);
      console.log("subscription complete");
  },
  err => console.error(err),
  () => {
      this.sharedData.tabSet.select(id);
      console.log(this.sharedData.tabSet.activeId);
      console.log('done');
  }
);


setTimeout(() => {
    this._watch = Observable.from(this.ngbTabset.tabs);
    this._watch.subscribe(
      x => console.log('onNext: %s', x),
      e => console.log('onError: %s', e),
      () => {
          var index = this.ngbTabset.tabs.length - 1;
          var lastTab = this.ngbTabset.tabs.last;
          console.log(this.ngbTabset.tabs);
          console.log(index);
          console.log(lastTab);
          this.ngbTabset.select(lastTab.id);
          console.log('onCompleted');
      });
})
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;

module.exports.translate = function(load){
  if (load.source.indexOf('moduleId') != -1) return load;

  var url = document.createElement('a');
  url.href = load.address;

  var basePathParts = url.pathname.split('/');

  basePathParts.pop();
  var basePath = basePathParts.join('/');

  var baseHref = document.createElement('a');
  baseHref.href = this.baseURL;
  baseHref = baseHref.pathname;

  if (!baseHref.startsWith('/base/')) { // it is not karma
    basePath = basePath.replace(baseHref, '');
  }

  load.source = load.source
    .replace(templateUrlRegex, function(match, quote, url){
      var resolvedUrl = url;

      if (url.startsWith('.')) {
        resolvedUrl = basePath + url.substr(1);
      }

      return 'templateUrl: "' + resolvedUrl + '"';
    })
    .replace(stylesRegex, function(match, relativeUrls) {
      var urls = [];

      while ((match = stringRegex.exec(relativeUrls)) !== null) {
        if (match[2].startsWith('.')) {
          urls.push('"' + basePath + match[2].substr(1) + '"');
        } else {
          urls.push('"' + match[2] + '"');
        }
      }

      return "styleUrls: [" + urls.join(', ') + "]";
    });

  return load;
};