-
Notifications
You must be signed in to change notification settings - Fork 0
/
dropdowns-json.component.ts
76 lines (70 loc) · 1.86 KB
/
dropdowns-json.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Component } from '@angular/core';
import { ComponentEvent } from '@ngx-dynamic-components/core';
@Component({
selector: 'app-dropdowns-json',
template: `
<ngx-dynamic-component
[uiModel]="uiModel"
(eventHandlers)="eventHandlers($event)"
[dataModel]="data">
</ngx-dynamic-component>
`
})
export class DropdownsJsonComponent {
uiModel = {
type: 'div',
itemProperties: {
class: 'flex-column',
maxWidth: '300px'
},
children: [{
type: 'h3',
itemProperties: { content: 'Select City' }
}, {
type: 'div',
itemProperties: { class: 'form-group' },
children: [{
type: 'label',
itemProperties: { class: 'col-form-label', width: '60px', text: 'Country' }
}, {
type: 'ng-select',
itemProperties: {
onSelect: 'countryChanged',
width: '300px',
binding: '$.country',
itemsSource: [
{ label: 'United Kingdom', value: 'uk' },
{ label: 'Ukraine', value: 'ua' }
],
multiple: false
}
}]
}, {
type: 'div',
itemProperties: { class: 'form-group' },
children: [{
type: 'label',
itemProperties: { class: 'col-form-label', width: '60px', text: 'City' }
},
{
type: 'ng-select',
itemProperties: { width: '300px', itemsSource: '$.cities', binding: '$.city', multiple: false }
}]
}]
};
data = {
city: null,
country: null,
cities: null
};
private cities = {
uk: [{ label: 'London', value: 'lon' }, { label: 'Liverpool', value: 'liv' }],
ua: [{ label: 'Kyiv', value: 'kyiv' }, { label: 'Lviv', value: 'lvi' }]
};
eventHandlers(evt: ComponentEvent) {
if (evt.eventName === 'countryChanged') {
this.data.cities = this.cities[this.data.country];
this.data.city = null;
}
}
}