Skip to content
GitLab
Explore
Sign in
Commits on Source (5)
add contact list
· 75f12520
Oleksandr Kotov
authored
Sep 18, 2017
75f12520
add new contact form
· 8baad800
Oleksandr Kotov
authored
Sep 18, 2017
8baad800
add contact selection
· 5dce31b1
Oleksandr Kotov
authored
Sep 18, 2017
5dce31b1
add selection highlight
· 32cb6317
Oleksandr Kotov
authored
Sep 18, 2017
32cb6317
add contact editor
· 25e6e52e
Oleksandr Kotov
authored
Sep 18, 2017
25e6e52e
Hide whitespace changes
Inline
Side-by-side
src/app/app.component.html
View file @
25e6e52e
<h1>
Welcome to {{title}}!
</h1>
<h2>
Contacts
</h2>
<ul>
<li
*ngFor=
"let contact of contacts"
(click)=
"selectContact(contact)"
[class.selected]=
"isSelected(contact)"
>
{{contact.name}}
</li>
</ul>
<div
*ngIf=
"selectedContact"
>
<h2>
{{selectedContact.name}}
</h2>
<input
type=
"text"
[(ngModel)]=
"selectedContact.name"
>
</div>
<h2>
New Contact
</h2>
<form
(submit)=
"addContact()"
>
<input
type=
"text"
name=
"name"
[(ngModel)]=
"contactName"
>
<button
type=
"submit"
>
Add contact {{contactName}}
</button>
</form>
src/app/app.component.scss
View file @
25e6e52e
h1
{
color
:
blueviolet
;
}
li
{
cursor
:
pointer
;
}
li
.selected
{
background-color
:
lightblue
;
}
src/app/app.component.ts
View file @
25e6e52e
...
...
@@ -6,5 +6,28 @@ import { Component } from '@angular/core';
styleUrls
:
[
'
./app.component.scss
'
]
})
export
class
AppComponent
{
selectedContact
:
{
name
:
string
};
title
=
'
Angular on Fire Chat
'
;
contactName
=
''
;
contacts
=
[
{
name
:
'
Rob
'
},
{
name
:
'
Ed
'
},
{
name
:
'
Jon
'
}
];
addContact
()
{
this
.
contacts
.
push
({
name
:
this
.
contactName
});
this
.
contactName
=
''
;
}
selectContact
(
contact
)
{
this
.
selectedContact
=
contact
;
}
isSelected
(
contact
):
boolean
{
return
this
.
selectedContact
==
contact
;
}
}
src/app/app.module.ts
View file @
25e6e52e
import
{
BrowserModule
}
from
'
@angular/platform-browser
'
;
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
FormsModule
}
from
'
@angular/forms
'
import
{
AppComponent
}
from
'
./app.component
'
;
...
...
@@ -8,7 +9,8 @@ import { AppComponent } from './app.component';
AppComponent
],
imports
:
[
BrowserModule
BrowserModule
,
FormsModule
],
providers
:
[],
bootstrap
:
[
AppComponent
]
...
...