Skip to content

Commit f450f37

Browse files
author
Eric Anderson
committed
Connect Angular 2 application to API. Redo Aurelia application using JavaScriptServices.
1 parent 669390f commit f450f37

File tree

139 files changed

+1208
-49704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1208
-49704
lines changed

ASP.NET Core Basics/src/Angular/ClientApp/app/app.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AppComponent } from './components/app/app.component'
55
import { NavMenuComponent } from './components/navmenu/navmenu.component';
66
import { HomeComponent } from './components/home/home.component';
77
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
8+
import { ContactListComponent } from './components/contacts/contactlist.component';
89
import { CounterComponent } from './components/counter/counter.component';
910

1011
@NgModule({
@@ -14,6 +15,7 @@ import { CounterComponent } from './components/counter/counter.component';
1415
NavMenuComponent,
1516
CounterComponent,
1617
FetchDataComponent,
18+
ContactListComponent,
1719
HomeComponent
1820
],
1921
imports: [
@@ -23,6 +25,7 @@ import { CounterComponent } from './components/counter/counter.component';
2325
{ path: 'home', component: HomeComponent },
2426
{ path: 'counter', component: CounterComponent },
2527
{ path: 'fetch-data', component: FetchDataComponent },
28+
{ path: 'contact-list', component: ContactListComponent },
2629
{ path: '**', redirectTo: 'home' }
2730
])
2831
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Injectable } from '@angular/core';
2+
import { Http } from '@angular/http';
3+
import 'rxjs/add/operator/toPromise';
4+
import { Contact } from './contact';
5+
6+
@Injectable()
7+
export class ContactService {
8+
9+
constructor(private http: Http) {
10+
}
11+
12+
getAll(): Promise<Contact[]> {
13+
return this.http.get('http://localhost:13322/api/contactsApi/')
14+
.toPromise()
15+
.then(response => response.json())
16+
.then(contacts => Array.from(contacts, c => new Contact(c)))
17+
.catch(error => console.log(error));
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
export class Contact {
2+
id: number;
3+
name: string;
4+
address: string;
5+
city: string;
6+
state: string;
7+
postalCode: string;
8+
phone: string;
9+
email: string;
10+
211
constructor(data) {
312
Object.assign(this, data);
413
}
514

615
getAddress() {
716
return `${this.address} ${this.city}, ${this.state} ${this.postalCode}`;
817
}
18+
919
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ul>
2+
<li *ngFor="let contact of contacts">
3+
<h4>{{contact.name}}</h4>
4+
<p>{{contact.getAddress()}}</p>
5+
</li>
6+
</ul>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Contact } from './contact';
3+
import { ContactService } from './contact.service';
4+
5+
@Component({
6+
selector: 'contactlist',
7+
template: require('./contactlist.component.html'),
8+
providers: [ContactService]
9+
})
10+
export class ContactListComponent implements OnInit {
11+
contacts: Contact[];
12+
13+
constructor(private contactService: ContactService) { }
14+
15+
ngOnInit(): void {
16+
this.contactService.getAll()
17+
.then(contacts => this.contacts = contacts);
18+
}
19+
}

ASP.NET Core Basics/src/Angular/ClientApp/app/components/navmenu/navmenu.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<span class='glyphicon glyphicon-th-list'></span> Fetch data
2828
</a>
2929
</li>
30+
<li [routerLinkActive]="['link-active']">
31+
<a [routerLink]="['/contact-list']">
32+
<span class='glyphicon glyphicon-list-alt'></span> Contact List
33+
</a>
34+
</li>
3035
</ul>
3136
</div>
3237
</div>

ASP.NET Core Basics/src/Angular/ClientApp/dist/main-server.js

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

ASP.NET Core Basics/src/Angular/wwwroot/dist/0.47ba883e9351f8fef994.hot-update.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ASP.NET Core Basics/src/Angular/wwwroot/dist/0.60e9b52aa8a479d15a00.hot-update.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ASP.NET Core Basics/src/Angular/wwwroot/dist/main-client.js

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

0 commit comments

Comments
 (0)