import {AfterViewInit, Component, ElementRef} from '@angular/core'; import {IOption} from 'ng-select'; declare var hljs: any; import {OptionService} from '../../services/option.service'; @Component({ selector: 'ng-model', templateUrl: './ng-model.component.html' }) export class NgModel implements AfterViewInit { characters: Array = this.optionService.getCharacters(); selectedCharacter: string = '3'; selectedCharacters: Array = ['1', '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]); } } html0: string = `
Selected option: {{selectedCharacter}}
<ng-select
    [options]="characters"
    [(ngModel)]="selectedCharacter">
</ng-select>
<button
    (click)="selectedCharacter='1'">
    Select Art3mis
</button>
`; ts0: string = `
export class NgModelExample {

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

    constructor(
        private optionService: OptionService
    ) {}
}
`; html1: string = `
Selected options: {{selectedCharacter}}
<ng-select
    [options]="characters"
    [multiple]="true"
    [(ngModel)]="selectedCharacters">
</ng-select>
<button
    (click)="selectedCharacters = ['2', '4']">
    Select Daito and Shoto
</button>
`; ts1: string = `
export class NgModelExample {

    characters: Array<IOption> = this.optionService.getCharacters();
    selectedCharacters: Array<string> = ['1', '3'];

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