Skip to content
Commits on Source (2)
......@@ -17,7 +17,7 @@
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"prefix": "",
"styles": [
"styles.scss"
],
......
......@@ -5,15 +5,10 @@
</nav>
<aside>
<h2>Contacts</h2>
<ul>
<li
*ngFor="let contact of contacts"
(click)="selectContact(contact)"
[class.selected]="isSelected(contact)">
{{contact.name}}
</li>
</ul>
<contact-list
[contacts]="contacts"
(select)="selectContact($event)">
</contact-list>
<h2>New Contact</h2>
<form (submit)="addContact()">
......@@ -27,9 +22,7 @@
</form>
</aside>
<main *ngIf="selectedContact">
<h2>{{selectedContact.name}}</h2>
<input
type="text"
[(ngModel)]="selectedContact.name">
</main>
<contact-detail
*ngIf="selectedContact"
[contact]="selectedContact">
</contact-detail>
......@@ -15,43 +15,19 @@ h1 {
@extend .navbar-brand;
}
h2 {
margin-top: 20px;
}
aside {
@extend .col-4;
}
main {
contact-detail {
@extend .col-8;
}
input[type="text"] {
@extend .form-control;
}
button {
@extend .btn;
@extend .btn-primary;
}
ul {
@extend .list-group;
}
ul>li {
@extend .list-group-item;
}
li {
cursor: pointer;
}
li.selected {
@extend .active
}
form button {
margin-top: 10px;
}
......@@ -27,7 +27,4 @@ export class AppComponent {
this.selectedContact = contact;
}
isSelected(contact): boolean {
return this.selectedContact == contact;
}
}
......@@ -3,10 +3,14 @@ import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'
import { AppComponent } from './app.component';
import { ContactDetailComponent } from './contact/contact-detail/contact-detail.component';
import { ContactListComponent } from './contact/contact-list/contact-list.component';
@NgModule({
declarations: [
AppComponent
AppComponent,
ContactDetailComponent,
ContactListComponent
],
imports: [
BrowserModule,
......
<h2>{{contact.name}}</h2>
<input type="text" [(ngModel)]="contact.name">
import { Component, Input } from '@angular/core';
@Component({
selector: 'contact-detail',
templateUrl: './contact-detail.component.html',
styleUrls: ['./contact-detail.component.scss']
})
export class ContactDetailComponent {
@Input() contact;
}
<h2>Contacts</h2>
<ul>
<li
*ngFor="let contact of contacts"
(click)="selectContact(contact)"
[class.selected]="isSelected(contact)">
{{contact.name}}
</li>
</ul>
@import '../../../styles';
ul {
@extend .list-group;
}
ul>li {
@extend .list-group-item;
}
li {
cursor: pointer;
}
li.selected {
@extend .active
}
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
@Component({
selector: 'contact-list',
templateUrl: './contact-list.component.html',
styleUrls: ['./contact-list.component.scss']
})
export class ContactListComponent {
selectedContact: any;
@Input() contacts;
@Output() select = new EventEmitter();
selectContact(contact) {
this.selectedContact = contact;
this.select.next(contact);
}
isSelected(contact): boolean {
return this.selectedContact == contact;
}
}
/* You can add global styles to this file, and also import other style files */
@import '../node_modules/bootstrap/scss/bootstrap';
h2 {
margin-top: 20px;
}
input[type="text"] {
@extend .form-control;
}