forked from Kawameka/code-bits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AngularCodeBits.js
43 lines (31 loc) · 970 Bytes
/
AngularCodeBits.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Code Bit #1
// Adding the router package to an Angular App
// and setting the initial routes
// add to app.module.ts
import { RouterModule, Routes } from '@angular/router';
// some default route examples
const appRoutes: Routes = [
{path:'', component:RootComponent},
{path:'register', component:RegisterComponent},
{path:'login', component:LoginComponent}
]
// add to imports
RouterModule.forRoot(appRoutes)
// add to app.component.html
<div class="container">
<router-outlet></router-outlet>
</div>
// End Code Bit #1
// Code Bit #2
// angular router link format
<a class="nav-link" href="#" routerLink="/">Text</a>
// End Code Bit #2
// Code Bit #3
// to pull an id from the URL
// set route to include ID
{path:'user/:id', component:UserDetailsComponent}
// within appropriate component
import { Router, ActivatedRoute, Params } from '@angular/router';
// within ngOninit function
this.id = this.route.snapshot.params['id'];
// End Code Bit #3