Skip to content

Commit adb7d7d

Browse files
committed
Moving it to its own module
Now the route http://localhost:4200/polls and http://localhost:4200/Welcome will load the page We can also add more app-poll-components like app-poll-Edit-component
1 parent 6b07543 commit adb7d7d

File tree

7 files changed

+56
-18
lines changed

7 files changed

+56
-18
lines changed

angular-playground/pollingApp/src/app/app-poll/app-poll.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
app-poll works!
33

44
<div class="row">
5-
<div class="col-sm-3">A </div>
6-
<div class="col-sm-6">B
5+
<div class="col-sm-3"></div>
6+
<div class="col-sm-6">
77
<p-chart type="doughnut" [data]="data" width="30vw" height="80vh"></p-chart>
88
<button type="button" pButton (click)="update($event)"></button>
99

1010
</div>
11-
<div class="col-sm-3">C </div>
11+
<div class="col-sm-3"></div>
1212
</div>
1313

1414

angular-playground/pollingApp/src/app/polls.data.ts renamed to angular-playground/pollingApp/src/app/app-poll/app-poll.data.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { InMemoryDbService } from 'angular-in-memory-web-api';
2-
import { Poll } from './Poll';
2+
import { AppPoll } from './app-poll';
33

4-
export class PollsData implements InMemoryDbService{
4+
export class AppPollData implements InMemoryDbService{
55

66

77
createDb(){
8-
const polls: Poll[] =
8+
const polls: AppPoll[] =
99
[{
1010
"id": 1,
1111
"title": "Is bitcoin worth the time and money that mining requires?",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule } from '@angular/router';
3+
import { ReactiveFormsModule } from '@angular/forms';
4+
5+
import { ChartModule } from 'primeng/primeng';
6+
7+
// Imports for loading & configuring the in-memory web api
8+
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
9+
import { AppPollData } from './app-poll.data';
10+
import { AppPollComponent } from './app-poll.component';
11+
12+
// import { ProductListComponent } from './product-list.component';
13+
// import { ProductDetailComponent } from './product-detail.component';
14+
// import { ProductEditComponent } from './product-edit.component';
15+
// import { ProductEditGuard } from './product-edit.guard';
16+
17+
@NgModule({
18+
imports: [
19+
ChartModule,
20+
21+
ReactiveFormsModule,
22+
InMemoryWebApiModule.forRoot(AppPollData),
23+
RouterModule.forChild([
24+
{ path: 'polls', component: AppPollComponent },
25+
{ path: 'polls/:id', component: AppPollComponent },
26+
{
27+
path: 'polls/:id/edit',
28+
//canDeactivate: [ProductEditGuard],
29+
component: AppPollComponent
30+
}
31+
])
32+
],
33+
declarations: [
34+
AppPollComponent,
35+
// ProductDetailComponent,
36+
// ProductEditComponent
37+
]
38+
})
39+
export class AppPollModule { }

angular-playground/pollingApp/src/app/poll.service.ts renamed to angular-playground/pollingApp/src/app/app-poll/app-poll.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Injectable} from '@angular/core';
22
import {HttpClient, HttpHeaders} from '@angular/common/http';
33

4-
import {Poll} from './Poll';
4+
import {AppPoll} from './app-poll';
55
import { Observable, of, throwError } from 'rxjs';
66
import { catchError, tap, map } from 'rxjs/operators';
77

@@ -11,8 +11,8 @@ export class PollService{
1111

1212
constructor(private http: HttpClient){}
1313

14-
getPolls(): Observable<Poll[]>{
15-
return this.http.get<Poll[]>(this.pollUrl)
14+
getPolls(): Observable<AppPoll[]>{
15+
return this.http.get<AppPoll[]>(this.pollUrl)
1616
.pipe(
1717
tap(data=> console.log(JSON.stringify(data))),
1818
catchError(this.handleError)

angular-playground/pollingApp/src/app/Poll.ts renamed to angular-playground/pollingApp/src/app/app-poll/app-poll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface Poll{
1+
export interface AppPoll{
22

33
id: number,
44
title: string,

angular-playground/pollingApp/src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { AppPollComponent } from 'src/app/app-poll/app-poll.component';
44

55
const routes: Routes = [
66
{path: 'welcome', component: AppPollComponent},
7-
//{path: '**', redirectTo: "welcome", pathMatch: "full"},
8-
//{path:'', redirectTo: "welcome", pathMatch: "full"}
7+
// {path: '**', redirectTo: "welcome", pathMatch: "full"},
8+
{path:'', redirectTo: "welcome", pathMatch: "full"}
99

1010
];
1111

angular-playground/pollingApp/src/app/app.module.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@ import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
33
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
44

5-
import { ChartModule } from 'primeng/primeng';
65

76
import { AppRoutingModule } from './app-routing.module';
87
import { AppComponent } from './app.component';
9-
import { AppPollComponent } from './app-poll/app-poll.component';
8+
//import { AppPollComponent } from './app-poll/app-poll.component';
109
import { from } from 'rxjs/internal/observable/from';
10+
import { AppPollModule } from './app-poll/app-poll.module';
1111

1212
//import { HttpClient } from '@angular/common/http';
1313

1414
@NgModule({
1515
declarations: [
16-
AppComponent,
17-
AppPollComponent
16+
AppComponent
1817
],
1918
imports: [
2019
// HttpClient,
20+
AppPollModule,
2121
BrowserModule,
2222
BrowserAnimationsModule,
23-
AppRoutingModule,
24-
ChartModule
23+
AppRoutingModule
2524
],
2625
providers: [],
2726
bootstrap: [AppComponent]

0 commit comments

Comments
 (0)