Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ASP.NET Core Basics/src/Angular/ClientApp/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { ContactListComponent } from './components/contacts/contactlist.component';
import { ContactDetailComponent } from './components/contacts/contactdetail.component';
import { CounterComponent } from './components/counter/counter.component';

@NgModule({
Expand All @@ -16,6 +17,7 @@ import { CounterComponent } from './components/counter/counter.component';
CounterComponent,
FetchDataComponent,
ContactListComponent,
ContactDetailComponent,
HomeComponent
],
imports: [
Expand All @@ -26,6 +28,7 @@ import { CounterComponent } from './components/counter/counter.component';
{ path: 'counter', component: CounterComponent },
{ path: 'fetch-data', component: FetchDataComponent },
{ path: 'contact-list', component: ContactListComponent },
{ path: 'contact-detail/:id', component: ContactDetailComponent },
{ path: '**', redirectTo: 'home' }
])
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ import { Contact } from './contact';

@Injectable()
export class ContactService {
baseUrl = 'http://localhost:13322/api/contactsApi/';

constructor(private http: Http) {
}

getAll(): Promise<Contact[]> {
return this.http.get('http://localhost:13322/api/contactsApi/')
return this.http.get(this.baseUrl)
.toPromise()
.then(response => response.json())
.then(contacts => Array.from(contacts, c => new Contact(c)))
.catch(error => console.log(error));
}

getById(id: string): Promise<Contact> {
return this.http.get(this.baseUrl + id)
.toPromise()
.then(response => response.json())
.then(contact => new Contact(contact))
.catch(error => console.log(error));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1>Contact Details</h1>
<hr />
<div *ngIf="contact">
<dl class="dl-horizontal">
<dt>ID</dt>
<dd>{{contact.id}}</dd>
<dt>Name</dt>
<dd>{{contact.name}}</dd>
<dt>Address</dt>
<dd>{{contact.getAddress()}}</dd>
<dt>Phone</dt>
<dd>{{contact.phone}}</dd>
<dt>Email</dt>
<dd>{{contact.email}}</dd>
</dl>
</div>
<a routerLink="/contact-list">Back to List</a>
<hr />
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import 'rxjs/add/operator/switchMap';
import { Contact } from './contact';
import { ContactService } from './contact.service';

@Component({
selector: 'contactdetail',
template: require('./contactdetail.component.html'),
providers: [ContactService]
})
export class ContactDetailComponent implements OnInit {
contact: Contact;

constructor(private route: ActivatedRoute,
private router: Router,
private contactService: ContactService) { }

ngOnInit(): void {
this.route.params
.switchMap((params: Params) => this.contactService.getById(params['id']))
.subscribe((contact :Contact) => this.contact = contact);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
<th>Email</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let contact of contacts">
<td>{{contact.id}}</td>
<td>{{contact.name}}</td>
<td>{{contact.getAddress()}}</td>
<td>{{contact.phone}}</td>
<td>{{contact.email}}</td>
<td><a [routerLink]="['/contact-detail', contact.id]" (click)="onSelect(contact)">Details</a></td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import { ContactService } from './contact.service';
})
export class ContactListComponent implements OnInit {
contacts: Contact[];
selectedContactId: number = null;

constructor(private contactService: ContactService) { }

ngOnInit(): void {
this.contactService.getAll()
.then(contacts => this.contacts = contacts);
}

onSelect(contact) {
this.selectedContactId = contact.id;
}
}
84 changes: 78 additions & 6 deletions ASP.NET Core Basics/src/Angular/ClientApp/dist/main-server.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading