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
function emailConditionallyRequiredValidator(formControl: AbstractControl) { | |
if (!formControl.parent) { | |
return null; | |
} | |
if (formControl.parent.get('myCheckbox').value) { | |
return Validators.required(formControl); | |
} | |
return null; | |
} |
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
this.myForm.get('myCheckbox').valueChanges | |
.subscribe(value => { | |
this.myForm.get('myEmailField').updateValueAndValidity(); | |
}); |
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
/** | |
* makes the field required if the predicate function returns true | |
*/ | |
function requiredIfValidator(predicate) { | |
return (formControl => { | |
if (!formControl.parent) { | |
return null; | |
} | |
if (predicate()) { | |
return Validators.required(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
function conditionalValidator(predicate, validator) { | |
return (formControl => { | |
if (!formControl.parent) { | |
return null; | |
} | |
if (predicate()) { | |
return validator(formControl); | |
} | |
return null; | |
}) |
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
// For example, you can pass multiple validators composed with Validator.compose | |
// if the myTextField has the word 'Illuminati' | |
conditionalValidator(() => this.myForm.get('myTextField').value.includes('Illuminati'), | |
Validators.compose([ | |
Validators.required, | |
Validators.pattern(/.*mason.*/) | |
]) | |
) |
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 { Injectable } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { HttpClient, HttpParams } from '@angular/common/http'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class ProductService { | |
private readonly URL = 'https://world.openfoodfacts.org/api/v0/product/'; |
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
export class ProductService { | |
private readonly URL = 'https://world.openfoodfacts.org/api/v0/product/'; | |
constructor(private http: HttpClient) { | |
} | |
cache = {}; | |
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
<fa-icon [icon]="['fas', 'coffee']" size="xs"></fa-icon> |
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
export class IconsModule { | |
constructor(library: FaIconLibrary) { | |
library.addIconPacks(far); | |
library.addIconPacks(fas); | |
library.addIconPacks(fasPro); | |
} | |
} |
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
npm run i18n && ng build --base-href / --aot --prod --stats-json |