Skip to content

Instantly share code, notes, and snippets.

View navix's full-sized avatar
❄️
Coding smart ;)

Oleksa Novyk navix

❄️
Coding smart ;)
View GitHub Profile
@navix
navix / nl2br.pipe.ts
Created January 5, 2023 20:04
nl2br pipe
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'nl2br',
standalone: true,
})
export class Nl2brPipe implements PipeTransform {
transform(text: string): string {
return Nl2brPipe.replace(text);
}
@navix
navix / NG_PRETTIER_SETUP.md
Last active September 12, 2023 02:36
My Prettier setup for Angular apps
$ npm i prettier prettier-plugin-css-order prettier-plugin-organize-attributes css-declaration-sorter -D

Create .prettierrc file:

{
  "printWidth": 120,
 "tabWidth": 2,
@navix
navix / local-storage.ts
Last active April 11, 2024 09:04
Angular LocalStorage/SessionStorage services. Universal (SSR) compatible.
import { Platform } from '@angular/cdk/platform';
import { Injectable } from '@angular/core';
import { MemoryStorage } from './memory-storage';
@Injectable({
providedIn: 'root',
})
export class LocalStorage implements Storage {
private readonly storage: Storage;
@navix
navix / text-to-speech.ts
Created July 17, 2020 16:58
google text-to-speech
import { existsSync, mkdirSync } from 'fs';
import { resolve } from 'path';
import { config } from '../config';
export async function processTextToSpeech(ssml: string, filename: string) {
// Check media dir
const dirPath = resolve(config.main.storePath);
if (!existsSync(dirPath)) {
mkdirSync(dirPath);
}
@navix
navix / README.md
Last active May 13, 2019 11:51
Bind ngModel controls to ngForm from parent component

Bind ngModel controls to ngForm from parent component

This allows you to split a template-driven form on components.

Create formProvider directive to proxy ngModel injector from parent to child:

import { Directive, SkipSelf, forwardRef } from '@angular/core';
import { ControlContainer, Form } from '@angular/forms';
@navix
navix / readme.md
Last active February 4, 2023 18:40
Typescript advanced built-in types
@navix
navix / readme.md
Created February 11, 2019 12:10
Add nodes just after a component (not inside) in Angular 7

Add nodes just after a component (not inside) in Angular 7

For example we have radio-input and want to create a custom view. But no elements allowed inside input element.

<label>
  <input type="radio" uiRadio ...>
  Option A
</label>
@navix
navix / readme.md
Created February 11, 2019 11:57
Import JSON into Angular 7 during build

Import JSON into Angular 7 during build

typings.d.ts

declare module '*.json' {
  const value: any;
  export default value;
}
@navix
navix / readme.md
Created February 11, 2019 11:39
Wait for all animations to finish before :leave in Angular 7 (@angular/animations)

Wait for all animations to finish before :leave in Angular 7

Including child components.

@Component({
  ...
  animations: [
    trigger('host', [
 transition(':enter, :leave', [
@navix
navix / readme.md
Created February 11, 2019 11:31
Proxy in Angular CLI 7

Proxy in Angular CLI 7

For example proxy GraphQL requests from the default Angular CLI port to your API server.

localhost:4200/graphql -> localhost:3000/graphql

proxy.conf.json