Skip to content

Commit 45d458f

Browse files
authored
Merge pull request #4 from alisaduncan/routing
Routing
2 parents de34f26 + a4bb4a1 commit 45d458f

30 files changed

+858
-803
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A working version of the application can be found at [https://alisaduncan.github
55

66
This project was an opportunity for me to play with Angular, RxJS, and Material. The app calls [JSONPlaceholder](https://jsonplaceholder.typicode.com/) API to retrieve users and POST a new user. The code contains examples on utilizing Angular's HttpClient and corresponding unit tests. Unit tests for the view have been disabled for now.
77

8-
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.2.7.
8+
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.
99

1010
## Prerequisites
1111

angular.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"src/favicon.ico"
2222
],
2323
"styles": [
24-
"src/styles.css"
24+
"src/styles.scss"
2525
],
2626
"scripts": []
2727
},
@@ -122,7 +122,7 @@
122122
"schematics": {
123123
"@schematics/angular:component": {
124124
"prefix": "app",
125-
"styleext": "css"
125+
"styleext": "scss"
126126
},
127127
"@schematics/angular:directive": {
128128
"prefix": "app"

package-lock.json

Lines changed: 553 additions & 644 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",
7-
"start": "ng serve --open",
8-
"build": "ng build",
7+
"start": "ng serve --aot --open",
8+
"build": "ng build --prod",
9+
"build:docs": "ng build --prod --base-href https://alisaduncan.github.io/tutorial-angular-httpclient/",
910
"test": "ng test",
1011
"lint": "ng lint",
1112
"e2e": "ng e2e"
1213
},
1314
"private": true,
1415
"dependencies": {
15-
"@angular/animations": "^6.0.3",
16-
"@angular/cdk": "^6.2.0",
17-
"@angular/common": "^6.0.3",
18-
"@angular/compiler": "^6.0.3",
19-
"@angular/core": "^6.0.3",
20-
"@angular/flex-layout": "^6.0.0-beta.16",
21-
"@angular/forms": "^6.0.3",
22-
"@angular/http": "^6.0.3",
23-
"@angular/material": "^6.2.1",
24-
"@angular/platform-browser": "^6.0.3",
25-
"@angular/platform-browser-dynamic": "^6.0.3",
26-
"@angular/router": "^6.0.3",
16+
"@angular/animations": "^6.1.0",
17+
"@angular/cdk": "^6.4.2",
18+
"@angular/common": "^6.1.0",
19+
"@angular/compiler": "^6.1.0",
20+
"@angular/core": "^6.1.0",
21+
"@angular/flex-layout": "^6.0.0-beta.17",
22+
"@angular/forms": "^6.1.0",
23+
"@angular/http": "^6.1.0",
24+
"@angular/material": "^6.4.2",
25+
"@angular/platform-browser": "^6.1.0",
26+
"@angular/platform-browser-dynamic": "^6.1.0",
27+
"@angular/router": "^6.1.0",
2728
"core-js": "^2.5.4",
2829
"hammerjs": "^2.0.8",
2930
"rxjs": "^6.0.0",
30-
"zone.js": "^0.8.26"
31+
"zone.js": "~0.8.26"
3132
},
3233
"devDependencies": {
33-
"@angular/compiler-cli": "^6.0.3",
34-
"@angular-devkit/build-angular": "~0.6.8",
35-
"typescript": "~2.7.2",
36-
"@angular/cli": "~6.0.8",
37-
"@angular/language-service": "^6.0.3",
34+
"@angular-devkit/build-angular": "~0.7.0",
35+
"@angular/cli": "~6.1.2",
36+
"@angular/compiler-cli": "^6.1.0",
37+
"@angular/language-service": "^6.1.0",
3838
"@types/jasmine": "~2.8.6",
3939
"@types/jasminewd2": "~2.0.3",
4040
"@types/node": "~8.9.4",
@@ -48,6 +48,7 @@
4848
"karma-jasmine-html-reporter": "^0.2.2",
4949
"protractor": "~5.3.0",
5050
"ts-node": "~5.0.1",
51-
"tslint": "~5.9.1"
51+
"tslint": "~5.9.1",
52+
"typescript": "~2.7.2"
5253
}
5354
}

src/app/app-routing.module.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NgModule } from '@angular/core';
2+
import { Routes, RouterModule } from '@angular/router';
3+
import { UsersComponent } from './users/users.component';
4+
5+
const routes: Routes = [
6+
{ path: '', redirectTo: '/users', pathMatch: 'full' },
7+
{ path: 'users', component: UsersComponent },
8+
{ path: '**', redirectTo: '/users', pathMatch: 'full' }
9+
];
10+
11+
@NgModule({
12+
imports: [RouterModule.forRoot(routes)],
13+
exports: [RouterModule]
14+
})
15+
export class AppRoutingModule { }

src/app/app.component.css

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/app/app.component.html

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
<div fxLayout="column" fxFlex>
1+
<div fxLayout="column" fxFlex class="app">
22
<mat-toolbar color="primary">
3-
Angular HttpClient
3+
Angular Sample
44
</mat-toolbar>
55

6+
<router-outlet></router-outlet>
7+
</div>
68

7-
<mat-nav-list>
8-
<mat-list-item *ngFor="let user of users" (click)="selectedUser = user">
9-
<mat-icon matListAvatar svgIcon="avatars:{{user.avatar}}" class="avatar"></mat-icon>
10-
<h1 mat-line>{{ user.name }}</h1>
11-
<h6 mat-line>{{ user.bs }}</h6>
12-
</mat-list-item>
13-
</mat-nav-list>
14-
15-
<button mat-fab (click)="openAdminDialog()" class="fab-bottom-right">
16-
<mat-icon>add</mat-icon>
17-
</button>
189

19-
</div>
2010

src/app/app.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.app {
2+
3+
}
4+

src/app/app.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('AppComponent', () => {
1616
}).compileComponents();
1717
}));
1818

19-
xit('should create the app', async(() => {
19+
it('should create the app', async(() => {
2020
const fixture = TestBed.createComponent(AppComponent);
2121
const app = fixture.debugElement.componentInstance;
2222
expect(app).toBeTruthy();
@@ -28,10 +28,10 @@ describe('AppComponent', () => {
2828
expect(app.title).toEqual('app');
2929
}));
3030

31-
xit('should render title in a h1 tag', async(() => {
31+
xit('should render title in a mat-toolbar', async(() => {
3232
const fixture = TestBed.createComponent(AppComponent);
3333
fixture.detectChanges();
3434
const compiled = fixture.debugElement.nativeElement;
35-
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
35+
expect(compiled.querySelector('mat-toolbar').textContent).toContain('Angular Sample');
3636
}));
3737
});

src/app/app.component.ts

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,10 @@
1-
import { Component, OnInit } from '@angular/core';
2-
import { DomSanitizer } from '@angular/platform-browser';
3-
import { MatIconRegistry, MatDialog } from '@angular/material';
4-
5-
import { filter, map } from 'rxjs/operators';
6-
7-
import { UserService } from './user.service';
8-
import { User } from './user';
9-
import { DialogComponent } from './dialog/dialog.component';
1+
import { Component } from '@angular/core';
102

113
@Component({
124
selector: 'app-root',
135
templateUrl: './app.component.html',
14-
styleUrls: ['./app.component.css']
6+
styleUrls: ['./app.component.scss']
157
})
16-
export class AppComponent implements OnInit {
17-
public users: User[] = [];
18-
private selectedUser: User = new User;
19-
private name: string;
20-
private bs: string;
21-
22-
constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer, private userService: UserService, private dialog: MatDialog) {
23-
const avatarsSafeUrl = sanitizer.bypassSecurityTrustResourceUrl('./assets/avatars.svg');
24-
iconRegistry.addSvgIconSetInNamespace('avatars', avatarsSafeUrl);
25-
}
26-
27-
public ngOnInit() {
28-
this.userService.getUsers().subscribe(
29-
users => {
30-
this.users = users;
31-
this.selectedUser = this.users[0];
32-
}
33-
);
34-
}
35-
36-
public openAdminDialog() {
37-
this.dialog.open(DialogComponent).afterClosed()
38-
.subscribe(user => {
39-
if (!user.name || !user.bs) {
40-
return;
41-
}
8+
export class AppComponent {
429

43-
this.users.push({
44-
id: this.users.length + 1,
45-
name: user.name,
46-
bs: user.bs,
47-
avatar: 'svg-6'
48-
});
49-
this.selectedUser = user;
50-
this.userService.addUser(user).subscribe();
51-
});
52-
}
5310
}

0 commit comments

Comments
 (0)