const precision = '4';
const re = new RegExp('^[0-9]*\.[0-9]{' + precision + '}$');
//returns true
re.test('10.50')
//returns false
re.test('-120')
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
| // Source: https://github.com/typeorm/typeorm/issues/508 | |
| // Note: when we are referencing post we want to via non primary key, but by `postId` | |
| @OneToOne(() => PostInfo, (entity) => entity.postId) | |
| @JoinColumn({ name: 'postId', referencedColumnName: 'postId' }) | |
| post: PostInfo; |
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
| <ngx-slick-carousel class="carousel" [config]="carouselConfig" #slickCarousel> | |
| <div ngxSlickItem *ngFor="let item of vm.item; let i = index" | |
| class="py-5 text-center cursor-pointer"> | |
| {{ item.content }} | |
| </div> | |
| </label> | |
| </ngx-slick-carousel> |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Title of the document</title> | |
| </head> | |
| <body> | |
| <input type="number" name="test_name" min="0" oninput="validity.valid||(value='');"> | |
| </body> | |
| </html> |
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 { Renderer2, RendererFactory2 } from '@angular/core'; | |
| @Injectable() | |
| class Service { | |
| private renderer: Renderer2; | |
| constructor(rendererFactory: RendererFactory2) { | |
| this.renderer = rendererFactory.createRenderer(null, 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
| import { | |
| Directive, | |
| ElementRef, | |
| EventEmitter, | |
| OnDestroy, | |
| Output | |
| } from '@angular/core'; | |
| import ResizeObserver from 'resize-observer-polyfill'; | |
| const entriesMap = new WeakMap(); |
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
| enum Color { | |
| Red, | |
| Green, | |
| Blue | |
| } | |
| function getColorName(c: Color): string { | |
| switch (c) { | |
| case Color.Red: | |
| return "red"; |
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 { FormGroup, ValidationErrors, ValidatorFn } from '@angular/forms'; | |
| /** | |
| * Validates that at least one of the form controls is valid against `validator` function passed as the parameter. | |
| * @param validator Validation function, in example `Validators.required`. | |
| * @param controls Controls names. | |
| * @returns ValidationErrors or null if at least control is valid. | |
| * | |
| * @example | |
| * ```JS |
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
| /* | |
| credit to: https://stackoverflow.com/questions/46040077/how-to-implement-server-side-pagination-server-side-sorting-with-ngx-datatable | |
| The best way to handle both server-side pagination AND server-side sorting consist of: | |
| - having a page object which holds all the pagination and sorting information | |
| (like the order column, order direction, page number, page size, ...) which will be bound to the table | |
| - having a single function reloadTable() which calls the API to get the data using the data stored in the page object | |
| as parameters, automaticaly re-rendering the table | |
| - having a pageCallback which only updates the data contained in page relative to the pagination and then calls reloadTable() | |
| - having a sortCallback which only updates the data contained in page relative to the sorting and then calls reloadTable() | |
| */ |