Skip to content

Commit 36cbc32

Browse files
committed
update example to use "ngAfterViewChecked"
1 parent f5dc69d commit 36cbc32

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/app/home/home.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h4>Local State</h4>
4040
</tfoot>
4141
</table>
4242

43-
<form (ngSubmit)="submitState(localState.value)" autocomplete="off">
43+
<form (ngSubmit)="submitState(localState.data)" autocomplete="off">
4444

4545
<input
4646
[value]="localState.data[1].salary"

src/app/home/home.component.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
AfterContentChecked,
2+
AfterViewChecked,
33
Component,
44
OnInit
55
} from '@angular/core';
@@ -31,12 +31,11 @@ import { TableExport } from 'tableexport';
3131
*/
3232
templateUrl: './home.component.html'
3333
})
34-
export class HomeComponent implements OnInit, AfterContentChecked {
34+
export class HomeComponent implements OnInit, AfterViewChecked {
3535
/**
3636
* Set our default values
3737
*/
3838
public localState = {
39-
value: '' ,
4039
data: [
4140
{
4241
name: 'Thor Walton',
@@ -75,15 +74,13 @@ export class HomeComponent implements OnInit, AfterContentChecked {
7574
*/
7675
}
7776

78-
public ngAfterContentChecked() {
79-
this.te = new TableExport(document.querySelector('#default-table'), {
80-
formats: ['xlsx', 'xls', 'csv', 'txt']
81-
}).reset();
77+
public ngAfterViewChecked() {
78+
// NOTE: the `reset` is to prevent multiple renders on state change
79+
TableExport(document.querySelector('#default-table')).reset();
8280
}
8381

84-
public submitState(value: string) {
85-
console.log('submitState', value);
86-
this.appState.set('value', value);
87-
this.localState.value = '';
82+
public submitState(data: string) {
83+
console.log('submitState', data);
84+
this.appState.set('data', data);
8885
}
8986
}

0 commit comments

Comments
 (0)