Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
add contact detail component
· 3dadba22
Oleksandr Kotov
authored
Sep 19, 2017
3dadba22
add contact list component
· 5950fea5
Oleksandr Kotov
authored
Sep 19, 2017
5950fea5
Hide whitespace changes
Inline
Side-by-side
.angular-cli.json
View file @
5950fea5
...
...
@@ -17,7 +17,7 @@
"test"
:
"test.ts"
,
"tsconfig"
:
"tsconfig.app.json"
,
"testTsconfig"
:
"tsconfig.spec.json"
,
"prefix"
:
"
app
"
,
"prefix"
:
""
,
"styles"
:
[
"styles.scss"
],
...
...
src/app/app.component.html
View file @
5950fea5
...
...
@@ -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>
src/app/app.component.scss
View file @
5950fea5
...
...
@@ -15,43 +15,19 @@ h1 {
@extend
.navbar-brand
;
}
h2
{
margin-top
:
20px
;
}
aside
{
@extend
.col-4
;
}
m
ai
n
{
contact-det
ai
l
{
@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
;
}
src/app/app.component.ts
View file @
5950fea5
...
...
@@ -27,7 +27,4 @@ export class AppComponent {
this
.
selectedContact
=
contact
;
}
isSelected
(
contact
):
boolean
{
return
this
.
selectedContact
==
contact
;
}
}
src/app/app.module.ts
View file @
5950fea5
...
...
@@ -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
,
...
...
src/app/contact/contact-detail/contact-detail.component.html
0 → 100644
View file @
5950fea5
<h2>
{{contact.name}}
</h2>
<input
type=
"text"
[(ngModel)]=
"contact.name"
>
src/app/contact/contact-detail/contact-detail.component.scss
0 → 100644
View file @
5950fea5
src/app/contact/contact-detail/contact-detail.component.ts
0 → 100644
View file @
5950fea5
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
;
}
src/app/contact/contact-list/contact-list.component.html
0 → 100644
View file @
5950fea5
<h2>
Contacts
</h2>
<ul>
<li
*ngFor=
"let contact of contacts"
(click)=
"selectContact(contact)"
[class.selected]=
"isSelected(contact)"
>
{{contact.name}}
</li>
</ul>
src/app/contact/contact-list/contact-list.component.scss
0 → 100644
View file @
5950fea5
@import
'../../../styles'
;
ul
{
@extend
.list-group
;
}
ul
>
li
{
@extend
.list-group-item
;
}
li
{
cursor
:
pointer
;
}
li
.selected
{
@extend
.active
}
src/app/contact/contact-list/contact-list.component.ts
0 → 100644
View file @
5950fea5
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
;
}
}
src/styles.scss
View file @
5950fea5
/* 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
;
}