Reputation: 766
i am using angular 4 check box tree structure,i want to know
how to write onload function in angular 4?
ang.component.ts
This is my component for tree view
import { Component, ViewChild } from '@angular/core';
import { TreeViewComponent } from '@syncfusion/ej2-ng-navigations';
@Component({
selector: 'app-checkboxes',
templateUrl: './checkboxes.component.html'
})
export class CheckboxesComponent {
//@ViewChild('samples')
constructor() {
}
public countries: Object[] = [
{ id: 1, name: 'Australia', hasChild: true, expanded: true },
{ id: 2, pid: 1, name: 'New South Wales', isChecked: true },
{ id: 3, pid: 1, name: 'Victoria' },
{ id: 4, pid: 1, name: 'South Australia' },
{ id: 6, pid: 1, name: 'Western Australia', isChecked: true },
{ id: 7, name: 'Brazil', hasChild: true },
{ id: 8, pid: 7, name: 'Paraná' },
{ id: 9, pid: 7, name: 'Ceará' },
{ id: 10, pid: 7, name: 'Acre' },
{ id: 11, name: 'China', hasChild: true },
{ id: 12, pid: 11, name: 'Guangzhou' },
{ id: 13, pid: 11, name: 'Shanghai' },
{ id: 14, pid: 11, name: 'Beijing' },
{ id: 15, pid: 11, name: 'Shantou' },
{ id: 16, name: 'France', hasChild: true },
{ id: 17, pid: 16, name: 'Pays de la Loire' },
{ id: 18, pid: 16, name: 'Aquitaine' },
{ id: 19, pid: 16, name: 'Brittany' },
{ id: 20, pid: 16, name: 'Lorraine' },
{ id: 21, name: 'India', hasChild: true },
{ id: 22, pid: 21, name: 'Assam' },
{ id: 23, pid: 21, name: 'Bihar' },
{ id: 24, pid: 21, name: 'Tamil Nadu' },
{ id: 25, pid: 21, name: 'Punjab' }
];
public field: Object = {
dataSource: this.countries,
id: 'id',
parentID: 'pid',
text: 'name',
hasChildren: 'hasChild'
};
public showCheckBox: boolean = true;
public checkedNodes: string[] = ['2', '6'];
}
ang.component.html: This is my tree view structure using check boxes
<p>Angular 4 Checkbox Tree</p>
<div id='treeparent'>
<ej-treeview id='treeelement' [fields]='field'
[showCheckBox]='showCheckBox'> </ej-treeview>
</div>
Upvotes: 0
Views: 9892
Reputation: 574
If I understand correctly you're looking for ngOnInit which is normally used to setup things before the view loads. You can read more about it here
simple example:
export class Example implements OnInit{
constructor(){}
ngOnInit(){
//code that will execute at the start of the loading process
}
}
Upvotes: 1