Skip to content

Commit 5781090

Browse files
committed
Update demo
1 parent f7ceb79 commit 5781090

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

src/demo/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
import { FormsModule } from '@angular/forms';
4+
import { HttpClientModule } from '@angular/common/http';
45
import { TreeviewModule } from '../lib';
56
import { AppComponent } from './app.component';
67
import { AppRoutingModule } from './app-routing.module';
@@ -17,6 +18,7 @@ import { DisabledOnSelectorDirective } from './disabled-on-selector.directive';
1718
imports: [
1819
BrowserModule,
1920
FormsModule,
21+
HttpClientModule,
2022
TreeviewModule.forRoot(),
2123
DropdownTreeviewSelectModule,
2224
AppRoutingModule

src/demo/city/cities.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[{
2+
"name": "Ho Chi Minh",
3+
"postCode": 700000
4+
}, {
5+
"name": "Ha Noi",
6+
"postCode": 100000
7+
}, {
8+
"name": "Da Nang",
9+
"postCode": 550000
10+
}]

src/demo/city/city.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h3>Pipe & i18n (
66
<li>How to get unchecked items</li>
77
<li>i18n</li>
88
</ul>
9-
<div class="row">
9+
<div class="row" *ngIf="cities">
1010
<div class="col-12">
1111
<div class="alert alert-success" role="alert">
1212
Selected cities: {{selectedCities | json}}

src/demo/city/city.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export class CityComponent implements OnInit {
2222
) { }
2323

2424
ngOnInit() {
25-
this.cities = this.service.getCities();
25+
this.service.getCities().subscribe(cities => {
26+
this.cities = cities;
27+
});
2628
}
2729

2830
onSelectedChange(selectedCities: City[]) {

src/demo/city/city.service.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Injectable } from '@angular/core';
2+
import { HttpClient } from '@angular/common/http';
3+
import { Observable } from 'rxjs/Observable';
24

35
export interface City {
46
id: number;
@@ -8,23 +10,12 @@ export interface City {
810

911
@Injectable()
1012
export class CityService {
11-
getCities(): City[] {
12-
return [
13-
{
14-
id: 1,
15-
name: 'Ho Chi Minh',
16-
postCode: 700000
17-
},
18-
{
19-
id: 2,
20-
name: 'Ha Noi',
21-
postCode: 100000
22-
},
23-
{
24-
id: 3,
25-
name: 'Da Nang',
26-
postCode: 550000
27-
}
28-
];
13+
constructor(
14+
private httpClient: HttpClient
15+
) { }
16+
17+
getCities(): Observable<City[]> {
18+
const url = 'https://raw.githubusercontent.com/leovo2708/ngx-treeview/master/src/demo/city/cities.json';
19+
return this.httpClient.get<City[]>(url);
2920
}
3021
}

src/demo/product/product.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
</ng-template>
1717
<h3>Advanced (
18-
<a href="https://github.com/leovo2708/ngx-treeview/tree/master/src/demo/city" target="_blank">source code</a>)</h3>
18+
<a href="https://github.com/leovo2708/ngx-treeview/tree/master/src/demo/product" target="_blank">source code</a>)</h3>
1919
<ul>
2020
<li>Using custom TreeviewConfig to set new default configuration</li>
2121
<li>Using OrderDownlineTreeviewEventParser to get selection by order</li>

0 commit comments

Comments
 (0)