Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 6835737

Browse files
committed
docs(routerlink): Add Renderer2 support for
router-link-snippet component Fixes #1476
1 parent 1de329b commit 6835737

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

demo/src/app/advanced/router-link-snippet.component.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import { Component } from '@angular/core';
88
<section [innerHTML]="htmlSnippet" hljsContent=".xml"></section>
99
</div>
1010
<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>
1212
<section [innerHTML]="tsSnippet" hljsContent=".typescript"></section>
13+
<h4 class="header">Typescript (Angular v10.x and above)</h4>
14+
<section [innerHTML]="tsSnippetFor10Above" hljsContent=".typescript"></section>
1315
</div>
1416
`
1517
})
@@ -64,6 +66,52 @@ export class RouterLinkComponent implements AfterViewInit, OnInit {
6466
});
6567
}
6668
}</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>
67115
</pre>
68116
`;
69117
}

0 commit comments

Comments
 (0)