Skip to content

Commit

Permalink
Update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
leovo2708 committed Feb 1, 2018
1 parent f7ceb79 commit 5781090
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/demo/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { TreeviewModule } from '../lib';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
Expand All @@ -17,6 +18,7 @@ import { DisabledOnSelectorDirective } from './disabled-on-selector.directive';
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
TreeviewModule.forRoot(),
DropdownTreeviewSelectModule,
AppRoutingModule
Expand Down
10 changes: 10 additions & 0 deletions src/demo/city/cities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[{
"name": "Ho Chi Minh",
"postCode": 700000
}, {
"name": "Ha Noi",
"postCode": 100000
}, {
"name": "Da Nang",
"postCode": 550000
}]
2 changes: 1 addition & 1 deletion src/demo/city/city.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h3>Pipe & i18n (
<li>How to get unchecked items</li>
<li>i18n</li>
</ul>
<div class="row">
<div class="row" *ngIf="cities">
<div class="col-12">
<div class="alert alert-success" role="alert">
Selected cities: {{selectedCities | json}}
Expand Down
4 changes: 3 additions & 1 deletion src/demo/city/city.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export class CityComponent implements OnInit {
) { }

ngOnInit() {
this.cities = this.service.getCities();
this.service.getCities().subscribe(cities => {
this.cities = cities;
});
}

onSelectedChange(selectedCities: City[]) {
Expand Down
27 changes: 9 additions & 18 deletions src/demo/city/city.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

export interface City {
id: number;
Expand All @@ -8,23 +10,12 @@ export interface City {

@Injectable()
export class CityService {
getCities(): City[] {
return [
{
id: 1,
name: 'Ho Chi Minh',
postCode: 700000
},
{
id: 2,
name: 'Ha Noi',
postCode: 100000
},
{
id: 3,
name: 'Da Nang',
postCode: 550000
}
];
constructor(
private httpClient: HttpClient
) { }

getCities(): Observable<City[]> {
const url = 'https://raw.githubusercontent.com/leovo2708/ngx-treeview/master/src/demo/city/cities.json';
return this.httpClient.get<City[]>(url);
}
}
2 changes: 1 addition & 1 deletion src/demo/product/product.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>
</ng-template>
<h3>Advanced (
<a href="https://github.com/leovo2708/ngx-treeview/tree/master/src/demo/city" target="_blank">source code</a>)</h3>
<a href="https://github.com/leovo2708/ngx-treeview/tree/master/src/demo/product" target="_blank">source code</a>)</h3>
<ul>
<li>Using custom TreeviewConfig to set new default configuration</li>
<li>Using OrderDownlineTreeviewEventParser to get selection by order</li>
Expand Down

0 comments on commit 5781090

Please sign in to comment.