Skip to content

Commit 05addb2

Browse files
committed
add "dynamic" state example on home
1 parent 2f8fe83 commit 05addb2

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

src/app/home/home.component.html

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,11 @@ <h4>Local State</h4>
2323
</tr>
2424
</thead>
2525
<tbody>
26-
<tr>
27-
<td>Thor Walton</td>
28-
<td>Regional Director</td>
29-
<td>45</td>
30-
<td>$98,540</td>
31-
</tr>
32-
<tr>
33-
<td>Travis Clarke</td>
34-
<td>Software Engineer</td>
35-
<td>30</td>
36-
<td>$275,000</td>
37-
</tr>
38-
<tr>
39-
<td>Suki Burks</td>
40-
<td>Office Manager</td>
41-
<td>22</td>
42-
<td>$67,670</td>
26+
<tr *ngFor="let item of localState.data">
27+
<td>{{ item.name }}</td>
28+
<td>{{ item.position }}</td>
29+
<td>{{ item.age }}</td>
30+
<td>{{ item.salary }}</td>
4331
</tr>
4432
</tbody>
4533
<tfoot>
@@ -55,9 +43,9 @@ <h4>Local State</h4>
5543
<form (ngSubmit)="submitState(localState.value)" autocomplete="off">
5644

5745
<input
58-
[value]="localState.value"
59-
(input)="localState.value = $event.target.value"
60-
placeholder="Submit Local State to App State"
46+
[value]="localState.data[1].salary"
47+
(input)="localState.data[1].salary = $event.target.value"
48+
placeholder="Change my salary"
6149
autofocus>
6250

6351
<button>Submit Value</button>

src/app/home/home.component.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
2+
AfterContentChecked,
23
Component,
34
OnInit
45
} from '@angular/core';
56

67
import { AppState } from '../app.service';
78
import { Title } from './title';
89
import { XLargeDirective } from './x-large';
9-
import {TableExport} from 'tableexport';
10+
import { TableExport } from 'tableexport';
1011

1112
@Component({
1213
/**
@@ -30,11 +31,35 @@ import {TableExport} from 'tableexport';
3031
*/
3132
templateUrl: './home.component.html'
3233
})
33-
export class HomeComponent implements OnInit {
34+
export class HomeComponent implements OnInit, AfterContentChecked {
3435
/**
3536
* Set our default values
3637
*/
37-
public localState = { value: '' };
38+
public localState = {
39+
value: '' ,
40+
data: [
41+
{
42+
name: 'Thor Walton',
43+
position: 'Regional Director',
44+
age: 45,
45+
salary: '$98,540'
46+
},
47+
{
48+
name: 'Travis Clarke',
49+
position: 'Software Engineer',
50+
age: 30,
51+
salary: '$275,000'
52+
},
53+
{
54+
name: 'Suki Burks',
55+
position: 'Office Manager',
56+
age: 22,
57+
salary: '$67,670'
58+
}
59+
]
60+
};
61+
62+
public te: TableExport;
3863
/**
3964
* TypeScript public modifiers
4065
*/
@@ -50,10 +75,10 @@ export class HomeComponent implements OnInit {
5075
*/
5176
}
5277

53-
public ngAfterContentInit() {
54-
new TableExport(document.querySelector('#default-table'), {
78+
public ngAfterContentChecked() {
79+
this.te = new TableExport(document.querySelector('#default-table'), {
5580
formats: ['xlsx', 'xls', 'csv', 'txt']
56-
});
81+
}).reset();
5782
}
5883

5984
public submitState(value: string) {

0 commit comments

Comments
 (0)