Skip to content

Commit f131f33

Browse files
committed
docs: add material example
1 parent f817e94 commit f131f33

File tree

10 files changed

+163
-11
lines changed

10 files changed

+163
-11
lines changed

angular.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"src/assets"
2828
],
2929
"styles": [
30+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
3031
"src/styles.scss"
3132
],
3233
"scripts": [],
@@ -84,6 +85,7 @@
8485
"tsConfig": "src/tsconfig.spec.json",
8586
"karmaConfig": "src/karma.conf.js",
8687
"styles": [
88+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
8789
"src/styles.scss"
8890
],
8991
"scripts": [],

package-lock.json

Lines changed: 55 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/app-routing.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {NgModule} from '@angular/core';
22
import {RouterModule, Routes} from '@angular/router';
33
import {MainFromComponent} from './main-from/main-from.component';
4+
import {MaterialFromComponent} from './material-from/material-from.component';
45

56
const routes: Routes = [
67
{
@@ -11,6 +12,10 @@ const routes: Routes = [
1112
path: 'lazy',
1213
loadChildren: './lazy/lazy.module#LazyModule'
1314
},
15+
{
16+
path: 'material',
17+
component: MaterialFromComponent
18+
},
1419
{
1520
path: '',
1621
pathMatch: 'full',

src/app/app.module.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import {MainFromComponent} from './main-from/main-from.component';
1313
import {SharedModule} from './shared/shared.module';
1414
import {SimpleErrorPipe} from './simple-error-pipe.pipe';
1515
import {SimpleMessagesProviderService} from './simple-messages-provider.service';
16+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
17+
import {MatInputModule} from '@angular/material/input';
18+
import {MatButtonModule} from '@angular/material/button';
19+
import {MaterialFromComponent} from './material-from/material-from.component';
1620

1721
export function httpLoaderFactory(http: HttpClient): TranslateLoader {
1822
return new TranslateHttpLoader(http, '/assets/i18n/', '.json');
@@ -33,7 +37,8 @@ export function simpleCustomPipeFactoryCreator(messageProvider: SimpleMessagesPr
3337
AppComponent,
3438
CustomErrorsComponent,
3539
MainFromComponent,
36-
SimpleErrorPipe
40+
SimpleErrorPipe,
41+
MaterialFromComponent
3742
],
3843
imports: [
3944
AppRoutingModule,
@@ -50,6 +55,9 @@ export function simpleCustomPipeFactoryCreator(messageProvider: SimpleMessagesPr
5055
deps: [HttpClient]
5156
}
5257
}),
58+
MatInputModule,
59+
MatButtonModule,
60+
BrowserAnimationsModule,
5361
],
5462
providers: [
5563

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
.input-wrapper {
3+
position: relative;
4+
padding-bottom: 20px;
5+
}
6+
7+
form {
8+
width: 50%;
9+
margin: auto;
10+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<div style="width: 40%; text-align: center;margin: auto">
2+
<img src="assets/images/logo-blu.svg"/>
3+
</div>
4+
<h2 style="text-align: center">xtream validation errors</h2>
5+
<form [formGroup]="heroForm" validationContext="NEW_HERO" innerValidationError="true" #firstForm>
6+
7+
8+
<div style="display:flex;flex-direction: column;">
9+
<mat-form-field *ngxValidationErrors="heroForm.get('name'); errors as errors">
10+
<input matInput formControlName="name" placeholder="name"/>
11+
<mat-error *ngIf="errors">{{errors}}</mat-error>
12+
</mat-form-field>
13+
</div>
14+
15+
<div style="display:flex;flex-direction: column;">
16+
<mat-form-field *ngxValidationErrors="heroForm.get('surname'); errors as errors">
17+
<input matInput formControlName="surname" placeholder="surname"/>
18+
<mat-error *ngIf="errors">{{errors}}</mat-error>
19+
</mat-form-field>
20+
</div>
21+
22+
<button mat-raised-button color="primary" [disabled]="heroForm.invalid">Submit</button>
23+
<button mat-flat-button color="secondary" (click)="clearForm()">Clear</button>
24+
25+
</form>
26+
27+
<form [formGroup]="heroForm" validationContext="USER.REGISTRATION">
28+
<div style="display:flex;flex-direction: column;">
29+
<mat-form-field *ngxValidationErrors="heroForm.get('name');errors as errors">
30+
<input matInput formControlName="name" placeholder="name"/>
31+
<mat-error *ngIf="errors">{{errors}}</mat-error>
32+
</mat-form-field>
33+
</div>
34+
35+
<div style="display:flex;flex-direction: column;">
36+
<mat-form-field *ngxValidationErrors="heroForm.get('surname');errors as errors">
37+
<input matInput formControlName="surname" placeholder="surname"/>
38+
<mat-error *ngIf="errors">{{errors}}</mat-error>
39+
</mat-form-field>
40+
</div>
41+
42+
<button mat-raised-button color="primary" [disabled]="heroForm.invalid">Submit</button>
43+
44+
</form>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {Component, OnInit, ViewChild} from '@angular/core';
2+
import {FormControl, FormGroup, Validators} from '@angular/forms';
3+
import {TranslateService} from '@ngx-translate/core';
4+
import {ValidationContextComponent} from '@xtream/ngx-validation-errors';
5+
6+
@Component({
7+
selector: 'app-main-from',
8+
templateUrl: './material-from.component.html',
9+
styleUrls: ['./material-from.component.css']
10+
})
11+
export class MaterialFromComponent implements OnInit {
12+
13+
heroForm: FormGroup;
14+
@ViewChild('firstForm', {read: ValidationContextComponent}) validationContext: ValidationContextComponent;
15+
16+
constructor(private translateService: TranslateService) {
17+
this.heroForm = new FormGroup({
18+
name: new FormControl(null, [Validators.required, Validators.minLength(4)]),
19+
surname: new FormControl(null, [Validators.required, Validators.maxLength(1000)])
20+
});
21+
}
22+
23+
ngOnInit(): void {
24+
this.translateService.setDefaultLang('en');
25+
this.translateService.use('en');
26+
}
27+
28+
clearForm() {
29+
this.validationContext.clear();
30+
31+
}
32+
}

src/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<meta name="viewport" content="width=device-width, initial-scale=1">
99
<link rel="icon" type="image/x-icon" href="favicon.ico">
1010
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
11+
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
12+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
1113
</head>
1214
<body>
1315
<app-root></app-root>

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'hammerjs';
12
import { enableProdMode } from '@angular/core';
23
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
34

src/styles.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/* You can add global styles to this file, and also import other style files */
22

33

4+
5+
html, body { height: 100%; }
6+
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }

0 commit comments

Comments
 (0)