import { Component , Input , ChangeDetectionStrategy , ContentChild , TemplateRef , HostBinding , AfterContentInit , ChangeDetectorRef , OnChanges , OnDestroy } from '@angular/core' ; import { NglSelectInput } from '../input/input' ; import { toBoolean } from '../../util/convert' ; import { Subscription } from 'rxjs' ; @ Component ( { selector : 'ngl-select,[ngl-select]' , templateUrl : './select.html' , changeDetection : ChangeDetectionStrategy . OnPush , host : { '[class.slds-form-element]' : 'true' , } , } ) export class NglSelect implements OnChanges , AfterContentInit , OnDestroy { @ ContentChild ( NglSelectInput , { static : true } ) input : NglSelectInput ; @ Input ( ) label : string | TemplateRef < any > ; @ Input ( ) fieldLevelHelpTooltip : string | TemplateRef < any > ; @ Input ( ) error : string | TemplateRef < any > ; @ HostBinding ( 'class.slds-has-error' ) get hasError ( ) : boolean { return toBoolean ( this . error ) ; } required : boolean ; _uid : string ; get errorId ( ) { return `error_${ this . _uid }` ; } private ɵRequiredSubscription : Subscription ; constructor ( private cd ) { } ngOnChanges ( ) { this . input . describedBy = this . error ? this . errorId : null ; } ngAfterContentInit ( ) { if ( ! this . input ) { throw Error ( `[ng-lightning] Couldn't find an <select> with [ngl] attribute inside ngl-select` ) ; } this . ɵRequiredSubscription = this . input . ɵRequiredSubject . subscribe ( ( required ) => { this . required = required ; this . cd . detectChanges ( ) ; } ) ; this . _uid = this . input . id ; this . cd . detectChanges ( ) ; } ngOnDestroy ( ) { if ( this . ɵRequiredSubscription ) { this . ɵRequiredSubscription . unsubscribe ( ) ; this . ɵRequiredSubscription = null ; } } }