File tree Expand file tree Collapse file tree 6 files changed +26
-21
lines changed Expand file tree Collapse file tree 6 files changed +26
-21
lines changed Original file line number Diff line number Diff line change 1
1
import { NgModule } from '@angular/core' ;
2
2
import { BrowserModule } from '@angular/platform-browser' ;
3
3
import { FormsModule } from '@angular/forms' ;
4
+ import { HttpClientModule } from '@angular/common/http' ;
4
5
import { TreeviewModule } from '../lib' ;
5
6
import { AppComponent } from './app.component' ;
6
7
import { AppRoutingModule } from './app-routing.module' ;
@@ -17,6 +18,7 @@ import { DisabledOnSelectorDirective } from './disabled-on-selector.directive';
17
18
imports : [
18
19
BrowserModule ,
19
20
FormsModule ,
21
+ HttpClientModule ,
20
22
TreeviewModule . forRoot ( ) ,
21
23
DropdownTreeviewSelectModule ,
22
24
AppRoutingModule
Original file line number Diff line number Diff line change
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
+ }]
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ <h3>Pipe & i18n (
6
6
< li > How to get unchecked items</ li >
7
7
< li > i18n</ li >
8
8
</ ul >
9
- < div class ="row ">
9
+ < div class ="row " *ngIf =" cities " >
10
10
< div class ="col-12 ">
11
11
< div class ="alert alert-success " role ="alert ">
12
12
Selected cities: {{selectedCities | json}}
Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ export class CityComponent implements OnInit {
22
22
) { }
23
23
24
24
ngOnInit ( ) {
25
- this . cities = this . service . getCities ( ) ;
25
+ this . service . getCities ( ) . subscribe ( cities => {
26
+ this . cities = cities ;
27
+ } ) ;
26
28
}
27
29
28
30
onSelectedChange ( selectedCities : City [ ] ) {
Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
+ import { HttpClient } from '@angular/common/http' ;
3
+ import { Observable } from 'rxjs/Observable' ;
2
4
3
5
export interface City {
4
6
id : number ;
@@ -8,23 +10,12 @@ export interface City {
8
10
9
11
@Injectable ( )
10
12
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 ) ;
29
20
}
30
21
}
Original file line number Diff line number Diff line change 15
15
</ div >
16
16
</ ng-template >
17
17
< 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 >
19
19
< ul >
20
20
< li > Using custom TreeviewConfig to set new default configuration</ li >
21
21
< li > Using OrderDownlineTreeviewEventParser to get selection by order</ li >
You can’t perform that action at this time.
0 commit comments