import {AfterViewInit, Component, ElementRef} from '@angular/core'; import {IOption} from 'ng-select'; declare var hljs: any; import {OptionService} from '../../services/option.service'; @Component({ selector: 'allow-clear', templateUrl: './allow-clear.component.html' }) export class AllowClear implements AfterViewInit { characters: Array = this.optionService.getCharacters(); selectedCharacter: string = '3'; constructor( private elementRef: ElementRef, private optionService: OptionService ) {} ngAfterViewInit() { hljs.initHighlighting(); let nodes: NodeList = this.elementRef .nativeElement .querySelectorAll('.typescript, .html, .css'); for (let i = 0; i < nodes.length; i++) { hljs.highlightBlock(nodes[i]); } } html: string = `
<ng-select
    [options]="characters"
    [allowClear]="true"
    [(ngModel)]="selectedCharacter">
</ng-select>
`; ts: string = `
export class AllowClearExample {

    characters: Array<IOption> = this.optionService.getCharacters();
    selectedCharacter: string = '3';

    constructor(
        private optionService: OptionService
    ) {}
}
`; }