1 import { Component, forwardRef, Input, OnChanges } from '@angular/core'
2 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3 import { VideoChannel } from '@app/shared/shared-main'
4 import { SelectChannelItem } from '../../../../types/select-options-item.model'
7 selector: 'my-select-channel',
8 styleUrls: [ './select-shared.component.scss' ],
9 templateUrl: './select-channel.component.html',
12 provide: NG_VALUE_ACCESSOR,
13 useExisting: forwardRef(() => SelectChannelComponent),
18 export class SelectChannelComponent implements ControlValueAccessor, OnChanges {
19 @Input() items: SelectChannelItem[] = []
21 channels: SelectChannelItem[] = []
31 this.channels = this.items.map(c => {
32 const avatarPath = c.avatarPath
34 : VideoChannel.GET_DEFAULT_AVATAR_URL()
36 return Object.assign({}, c, { avatarPath })
40 propagateChange = (_: any) => { /* empty */ }
42 writeValue (id: number) {
46 registerOnChange (fn: (_: any) => void) {
47 this.propagateChange = fn
50 registerOnTouched () {
55 this.propagateChange(this.selectedId)