@@ -8,8 +8,10 @@ import { Component } from '@angular/core';
8
8
<section [innerHTML]="htmlSnippet" hljsContent=".xml"></section>
9
9
</div>
10
10
<div id="ts" class="col s12 m9 l12">
11
- <h4 class="header">Typescript</h4>
11
+ <h4 class="header">Typescript (Angular v9.x and below) </h4>
12
12
<section [innerHTML]="tsSnippet" hljsContent=".typescript"></section>
13
+ <h4 class="header">Typescript (Angular v10.x and above)</h4>
14
+ <section [innerHTML]="tsSnippetFor10Above" hljsContent=".typescript"></section>
13
15
</div>
14
16
`
15
17
} )
@@ -64,6 +66,52 @@ export class RouterLinkComponent implements AfterViewInit, OnInit {
64
66
});
65
67
}
66
68
}</code>
69
+ </pre>
70
+ ` ;
71
+
72
+ tsSnippetFor10Above = `
73
+ <pre>
74
+ <code class="typescript highlight">import { AfterViewInit, Component, OnInit, Renderer2 } from '@angular/core';
75
+ import { Router } from '@angular/router';
76
+
77
+ @Component({
78
+ selector: 'app-router-link',
79
+ templateUrl: 'router-link.component.html'
80
+ })
81
+ export class RouterLinkComponent implements AfterViewInit, OnInit {
82
+ dtOptions: DataTables.Settings = {};
83
+
84
+ constructor(private renderer: Renderer2, private router: Router) { }
85
+
86
+ ngOnInit(): void {
87
+ this.dtOptions = {
88
+ ajax: 'data/data.json',
89
+ columns: [{
90
+ title: 'ID',
91
+ data: 'id'
92
+ }, {
93
+ title: 'First name',
94
+ data: 'firstName'
95
+ }, {
96
+ title: 'Last name',
97
+ data: 'lastName'
98
+ }, {
99
+ title: 'Action',
100
+ render: function (data: any, type: any, full: any) {
101
+ return '<button class="waves-effect btn" view-person-id="' + full.id + '">View</button>';
102
+ }
103
+ }]
104
+ };
105
+ }
106
+
107
+ ngAfterViewInit(): void {
108
+ this.renderer.listen('document', 'click', (event) => {
109
+ if (event.target.hasAttribute("view-person-id")) {
110
+ this.router.navigate(["/person/" + event.target.getAttribute("view-person-id")]);
111
+ }
112
+ });
113
+ }
114
+ }</code>
67
115
</pre>
68
116
` ;
69
117
}
0 commit comments