-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropdowns.component.ts
More file actions
51 lines (45 loc) · 1.37 KB
/
dropdowns.component.ts
File metadata and controls
51 lines (45 loc) · 1.37 KB
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
import { Component } from '@angular/core';
import { ComponentEvent } from '@ngx-dynamic-components/core';
@Component({
selector: 'app-dropdowns',
template: `
<ngx-dynamic-component
[uiModel]="uiModel"
(eventHandlers)="eventHandlers($event)"
[dataModel]="data">
</ngx-dynamic-component>
`
})
export class DropdownsComponent {
uiModel = `
<div class="flex-column" maxWidth="300px">
<h3>Select City</h3>
<div class="form-group">
<label class="col-form-label" width="60px">Country</label>
<ng-select onSelect="countryChanged" width="300px" binding="$.country">
<option value="uk">United Kingdom</option>
<option value="ua">Ukraine</option>
</ng-select>
</div>
<div class="form-group">
<label class="col-form-label" width="60px">City</label>
<ng-select width="300px" itemsSource="$.cities" binding="$.city"></ng-select>
</div>
</div>
`;
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;
}
}
}