Skip to content

Commit 953e9d5

Browse files
committed
Session4 Routing
1 parent 20ac4ac commit 953e9d5

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

src/app/app.component.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<!--The content below is only a placeholder and can be replaced.-->
2-
<i class="material-icons">lightbulb_outline</i>
1+
2+
<div style="height:70px; width:100%;color:white; background-color:blue">
3+
Angular Sessions
4+
</div>
5+
36
<div style="text-align:center">
4-
<app-room></app-room>
7+
<router-outlet></router-outlet>
58
</div>
69

710

src/app/app.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { Component } from '@angular/core';
55
templateUrl: './app.component.html',
66
styleUrls: ['./app.component.css']
77
})
8-
export class AppComponent {
8+
export class AppComponent{
99
title = 'app';
1010
}

src/app/app.module.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
3+
import { RouterModule, Routes } from '@angular/router';
4+
35

46
import { AppComponent } from './app.component';
57
import { PersonComponent } from './component/person/person.component';
@@ -11,6 +13,14 @@ import { RoomComponent } from './component/room/room.component';
1113
import { LightSwitchService } from "app/light-switch.service";
1214

1315

16+
17+
const appRoutes: Routes = [
18+
{ path: '', component: RoomComponent },
19+
{ path: 'light', component: LightBulbComponent }
20+
];
21+
22+
23+
1424
@NgModule({
1525
declarations: [
1626
AppComponent,
@@ -22,7 +32,10 @@ import { LightSwitchService } from "app/light-switch.service";
2232
RoomComponent
2333
],
2434
imports: [
25-
BrowserModule
35+
BrowserModule,
36+
RouterModule.forRoot(
37+
appRoutes,
38+
)
2639
],
2740
providers: [LightSwitchService],
2841
bootstrap: [AppComponent]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<p>
22
Light Bulb Status: {{ isOn?'ON':'OFF' }}
33
</p>
4+
5+
<a routerLink="/" routerLinkActive="active"> Go to Home </a>

src/app/component/room/room.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
Room:
33
<app-ceiling></app-ceiling>
44
<app-wall></app-wall>
5+
<a routerLink="/light" routerLinkActive="active"> Go to Light </a>
56
</div>

0 commit comments

Comments
 (0)