Skip to content

Instantly share code, notes, and snippets.

View maximLyakhov's full-sized avatar
📐
angularing

Maxime Lyakhov maximLyakhov

📐
angularing
View GitHub Profile
@maximLyakhov
maximLyakhov / add & remove same element by clicking on another.js
Last active December 29, 2020 19:10
add & remove same element by clicking on another
const parentElement = document.querySelector('.parentElement')
const childElement = document.createElement('div')
document.querySelector('button').addEventListener('click', () => {
childElement.className = 'childElement'
if (parentElement.hasChildNodes()) {
document.querySelector('.parentElement').removeChild(document.querySelector('.childElement'))
} else {
parentElement.appendChild(childElement)
}
})
@maximLyakhov
maximLyakhov / angular recursive ngFor.html
Last active June 15, 2021 13:47
angular recursive ngFor
<ul>
<ng-container *ngTemplateOutlet="recursiveList; context: { list: dataSource.data }"></ng-container>
</ul>
<ng-template #recursiveList let-list="list">
<li *ngFor="let item of list">
<div *ngIf="item">
{{ item | json }}
<span>
{{ item.name }}
@maximLyakhov
maximLyakhov / component.ts
Created June 28, 2021 10:04
get only updated fields from angular forms
const updatedFormValues = {};
this.form['_forEachChild']((control, name) => {
if (control.dirty) {
updatedFormValue[name] = control.value;
}
});
@maximLyakhov
maximLyakhov / angular.json
Created July 24, 2021 11:38
angular routing on reg.ru
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
]
@maximLyakhov
maximLyakhov / list.html
Last active August 10, 2021 12:55
toggle inplace editing angular2+
<mat-list *ngIf="contracts">
<mat-list-item *ngFor="let contract of contracts">
<div class="row">
<span *ngIf="!contract.toggle">
{{ contractFunnel.name }}
</span>
<input matInput type="text" class="input" *ngIf="contract.toggle" [(ngModel)]="contract.name">
<ng-template [ngIf]="!contract.toggle" [ngIfElse]="editContract">
<mat-icon *ngIf="!contract.toggle" (click)="contract.toggle = true">
edit
@maximLyakhov
maximLyakhov / props.ts
Created August 10, 2021 13:45
pick only updated properties
export default function pickUpdatedProperties(current: any, sent: any) {
for (const key in current) {
if (current[key] && sent[key] && String(current[key]) === String(sent[key])) {
delete sent[key];
}
}
return sent;
}
@maximLyakhov
maximLyakhov / reports-routing.module.ts
Created August 23, 2021 14:29
angular nested routing
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ReportsComponent } from './reports.component';
const routes: Routes = [
{
path: '',
component: ReportsComponent,
children: [
{
@maximLyakhov
maximLyakhov / delay-between-each-request.js
Created January 4, 2022 21:53
The delay between each request.
const array = ["your", "response", "is", "here"];
const interval = 1000;
array.forEach((el, index) => {
setTimeout(() => {
console.log(`Request ${index + 1}:`, el);
}, index * interval);
});
@maximLyakhov
maximLyakhov / line-clamp.css
Created May 27, 2022 07:55
css text ellipsis
.your-class {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3; /* number of max lines */
}
/* https://stackoverflow.com/a/19049457 */
@mixin scrollbars($size, $foreground-color, $background-color: mix($foreground-color, white, 50%)) {
// For Google Chrome
&::-webkit-scrollbar {
width: $size;
height: $size;
}
&::-webkit-scrollbar-thumb {
background: $foreground-color;
}