This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update | |
sudo apt-get install nginx | |
# default website |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form [formGroup]="form"> | |
<div class="field"> | |
<input type="text" formControlName="name" /> | |
<app-validator [control]="form.get('name')"></app-validator> | |
</div> | |
<div class="field"> | |
<input type="text" formControlName="age" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if the validator has a custom validation message | |
* | |
* @param errors | |
* | |
* @return string | |
*/ | |
public message(errors: ValidationErrors | null): string { | |
const properties = Object.keys(errors); | |
let customMessage: boolean; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Input, OnInit } from '@angular/core'; | |
import { FormControl, FormGroup, ValidationErrors } from '@angular/forms'; | |
import { TranslateService } from '@ngx-translate/core'; | |
@Component({ | |
selector: 'app-validator', | |
templateUrl: './validator.component.html', | |
styleUrls: ['./validator.component.scss'] | |
}) | |
export class ValidatorComponent implements OnInit { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extract control name from formGroup | |
* | |
* @return string | |
*/ | |
public getControlName(): string { | |
let controlName = null; | |
const parent = this.control['parent']; | |
if (parent instanceof FormGroup) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"fields": { | |
"id": "ID", | |
"name": "Name", | |
"type": "Type", | |
"age": "Age", | |
"street_name": "Street name" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Input, OnInit } from '@angular/core'; | |
import { FormControl } from '@angular/forms'; | |
@Component({ | |
selector: 'app-validator', | |
templateUrl: './validator.component.html', | |
styleUrls: ['./validator.component.scss'] | |
}) | |
export class ValidatorComponent implements OnInit { | |
@Input() public control: FormControl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Input, OnInit } from '@angular/core'; | |
import { FormControl, FormGroup, ValidationErrors } from '@angular/forms'; | |
import { TranslateService } from '@ngx-translate/core'; | |
@Component({ | |
selector: 'app-validator', | |
templateUrl: './validator.component.html', | |
styleUrls: ['./validator.component.scss'] | |
}) | |
export class ValidatorComponent implements OnInit { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div.validator { | |
visibility: hidden; | |
margin-top: 5px; | |
min-height: 20px; | |
&.show { | |
visibility: visible; | |
} | |
p { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div [ngClass]="{show: control?.dirty || control?.touched}" class="validator"> | |
<ng-container *ngIf="control?.errors?.required"> | |
<p>{{ message(control?.errors) | translate: {field: name} }}</p> | |
</ng-container> | |
<ng-container *ngIf="control?.errors?.email"> | |
<p>{{ message(control?.errors) | translate: {field: name} }}</p> | |
</ng-container> | |
<ng-container *ngIf="control?.errors?.min"> |
NewerOlder