Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
single-page-application
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christopher Cottier
single-page-application
Commits
137e86fe
Commit
137e86fe
authored
Apr 21, 2021
by
ccottier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
account page created
parent
8f97e316
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
10 deletions
+123
-10
account.component.css
src/app/account/account.component.css
+15
-0
account.component.html
src/app/account/account.component.html
+65
-1
account.component.ts
src/app/account/account.component.ts
+37
-7
app.module.ts
src/app/app.module.ts
+5
-1
england.component.css
src/app/england/england.component.css
+1
-1
No files found.
src/app/account/account.component.css
View file @
137e86fe
.input
{
width
:
15em
;
height
:
2em
;
margin-bottom
:
1em
;
}
.invalid-text
{
color
:
red
;
}
.invalid-text
{
color
:
red
;
}
.ng-invalid.ng-touched
:not
(
form
)
{
border
:
2px
solid
red
;
}
\ No newline at end of file
src/app/account/account.component.html
View file @
137e86fe
<p>
account works!
</p>
<div>
<div
style=
"display:inline-block"
>
<form
[
formGroup
]="
userForm
"
(
ngSubmit
)="
onSubmit
()"
>
<div>
<p>
reactive
</p>
<div>
<input
type=
"text"
formControlName=
"firstName"
class=
"form-control input"
placeholder=
"First name"
>
</div>
<div>
<input
type=
"text"
formControlName=
"lastName"
class=
"form-control input "
placeholder=
"Last name"
>
</div>
</div>
<input
type=
"email"
formControlName=
"email"
class=
"form-control input"
placeholder=
"E-mail"
>
<div>
<button
type=
"submit"
>
Sign in
</button>
</div>
</form>
<div
>
<!-- <ngb-alert *ngIf="showMessage" type="danger" >{{ invalidEntry }}</ngb-alert> -->
<div
class=
"invalid-text"
*
ngIf=
"showMessage"
>
{{invalidEntry}}
</div>
</div>
</div>
<!-- template driven form -->
<div
style=
"display:inline-block; margin-left: 10em;"
>
<form
#
newUserForm=
"ngForm"
(
ngSubmit
)="
onSubmit2
(
newUserForm
)"
>
<div>
<p>
template-driven
</p>
<input
type=
"text"
class=
"input"
placeholder=
"User name"
required
[(
ngModel
)]="
userName
"
name=
"userName"
pattern=
"[a-zA-Z ]*"
#
pickedName=
"ngModel"
>
<div
*
ngIf=
"!pickedName.valid && pickedName.touched"
>
User name is required!
</div>
</div>
<div>
<input
type=
"email"
class=
"input"
placeholder=
"Email"
required
[(
ngModel
)]="
email
"
name=
"email"
#
userEmail=
"ngModel"
pattern=
"[a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}"
>
<div
*
ngIf=
"!userEmail.valid && userEmail.touched"
>
Email is not valid!
</div>
</div>
<div>
<input
type=
"password"
class=
"input"
placeholder=
"Password"
required
[(
ngModel
)]="
password
"
name=
"password"
#
userPassword=
"ngModel"
>
<div
*
ngIf=
"!userPassword.valid && userPassword.touched"
>
Password is required!
</div>
</div>
<button
type=
"submit"
[
disabled
]="!
newUserForm
.
form
.
valid
"
>
Register
</button>
<button
type=
"button"
(
click
)="
newUserForm
.
reset
()"
>
Reset
</button>
</form>
<!-- <pre>{{ newUserForm.form.value }}</pre> Value of whole form -->
<!-- <pre>User name: {{ pickedName.value }}</pre> Value of userName field -->
<pre>
Valid form? {{ newUserForm.form.valid }}
</pre>
</div>
</div>
src/app/account/account.component.ts
View file @
137e86fe
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
FormBuilder
,
Validators
}
from
'@angular/forms'
;
import
{
NgForm
}
from
'@angular/forms'
;
@
Component
({
@
Component
({
selector
:
'account'
,
selector
:
'a
pp-a
ccount'
,
templateUrl
:
'./account.component.html'
,
templateUrl
:
'./account.component.html'
,
styleUrls
:
[
'./account.component.css'
]
styleUrls
:
[
'./account.component.css'
]
})
})
export
class
AccountComponent
implements
OnInit
{
export
class
AccountComponent
implements
OnInit
{
public
userForm
;
constructor
()
{
}
public
showMessage
:
boolean
=
false
;
public
invalidEntry
=
'Invalid entry'
;
//template driven form
userName
=
''
;
email
:
string
;
nickName
:
string
;
password
:
string
;
constructor
(
private
formBuilder
:
FormBuilder
)
{
}
ngOnInit
():
void
{
ngOnInit
():
void
{
this
.
userForm
=
this
.
formBuilder
.
group
({
firstName
:
[
''
,
[
Validators
.
required
,
Validators
.
pattern
(
'^[a-zA-Z]+$'
)]],
lastName
:
[
''
,[
Validators
.
required
,
Validators
.
pattern
(
'^[a-zA-Z]+$'
)]],
email
:
[
''
,
[
Validators
.
required
,
Validators
.
pattern
(
'[a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}'
)]]
});
}
}
onSubmit
(){
}
if
(
this
.
userForm
.
valid
){
alert
(
'User form is valid!!'
)
}
else
{
alert
(
'User form is not valid!!'
)
}
}
onSubmit1
(){
if
(
!
this
.
userForm
.
valid
){
this
.
showMessage
=
true
;
}
}
//template driven
onSubmit2
(
form
:
NgForm
)
{
if
(
form
.
valid
)
{
console
.
log
(
form
.
value
);
// ...our form is valid, we can submit the data
}
}
}
\ No newline at end of file
src/app/app.module.ts
View file @
137e86fe
...
@@ -11,6 +11,8 @@ import { FranceComponent } from './france/france.component';
...
@@ -11,6 +11,8 @@ import { FranceComponent } from './france/france.component';
import
{
GreeceComponent
}
from
'./greece/greece.component'
;
import
{
GreeceComponent
}
from
'./greece/greece.component'
;
import
{
SpainComponent
}
from
'./spain/spain.component'
;
import
{
SpainComponent
}
from
'./spain/spain.component'
;
import
{
AccountComponent
}
from
'./account/account.component'
;
import
{
AccountComponent
}
from
'./account/account.component'
;
import
{
FormsModule
}
from
'@angular/forms'
;
import
{
ReactiveFormsModule
}
from
'@angular/forms'
;
@
NgModule
({
@
NgModule
({
declarations
:
[
declarations
:
[
...
@@ -26,7 +28,9 @@ import { AccountComponent } from './account/account.component';
...
@@ -26,7 +28,9 @@ import { AccountComponent } from './account/account.component';
imports
:
[
imports
:
[
BrowserModule
,
BrowserModule
,
AppRoutingModule
,
AppRoutingModule
,
NgbModule
NgbModule
,
FormsModule
,
ReactiveFormsModule
],
],
providers
:
[],
providers
:
[],
bootstrap
:
[
AppComponent
]
bootstrap
:
[
AppComponent
]
...
...
src/app/england/england.component.css
View file @
137e86fe
...
@@ -2,4 +2,4 @@
...
@@ -2,4 +2,4 @@
height
:
350px
;
height
:
350px
;
width
:
350px
;
width
:
350px
;
padding-left
:
5px
;
padding-left
:
5px
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment