Skip to content

Instantly share code, notes, and snippets.

View leifermendez's full-sized avatar
👋
Focusing

Leifer Mendez leifermendez

👋
Focusing
View GitHub Profile
@leifermendez
leifermendez / loading-btn.directive.ts
Last active March 15, 2021 11:23
loading-btn.directive.ts
import {Directive, ElementRef, Input, OnChanges, OnInit, Renderer2} from '@angular/core';
@Directive({
// tslint:disable-next-line:directive-selector
selector: '[ngxLoading]'
})
export class LoadingBtnDirective implements OnInit, OnChanges {
@Input() textLoading: string;
@Input() textInitial: string;
@leifermendez
leifermendez / api-checklist.md
Last active October 15, 2020 18:42
Project checklist
  • Soft Delete
  • Backup
  • Restore
  • Test
@leifermendez
leifermendez / example_1.ts
Created October 24, 2020 09:31
Subscribe & UnSubscribe
import { Component, OnDestroy, OnInit, VERSION } from "@angular/core";
import { SharedService } from "./shared.service";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit, OnDestroy {
/**
@leifermendez
leifermendez / example_2.ts
Last active March 24, 2021 13:29
Lazy Load
const routes: Routes = [
{
path: '',
component: HomeComponent,
children: [
{
path: 'auth',
loadChildren: './modules/auth/auth.module#AuthModule'
},
{
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const token = localStorage.getItem('auth_token');
if (!token) {
return next.handle(req);
}
export class AppComponent implements OnInit {
public data$: Observable<any>;
ngOnInit(): void {
this.data$ = this.rest.get(`http://api-data.com`)
}
}
<ul>
<li *ngFor="let item of data$ | async">
{{item}}
</li>
</ul>
search = (q: string, exportData = false, limit = 0) => {
this.results$.total = 0;
if (q.length > 2) {
this.results$.q = q;
this.loading = true;
const url = (exportData) ? `overview/search?q=${q}&export=xlsx&limit=${limit}` : `overview/search?q=${q}`;
this.results$.docs = this.rest.get(url,
true, {ignoreLoadingBar: ''})
.pipe(
@leifermendez
leifermendez / main.ts
Created December 10, 2020 13:05
Main.ts Angular
if (environment.production) {
enableProdMode();
if (window) {
window.console.log = window.console.warn = window.console.info = function () {
// Don't log anything.
};
const w = window as any;
window.console.error = function ($event, more) {
console.log(' 😠 ERROR', more)
// Se debe obtener la fecha en formato YYYY/MM/DD muy importante usar '/' para separar
const start = moment.utc('2020-07-13T14:04:45.098Z').format('YYYY/MM/DD') // 2020/07/13
// Luego se debe volver a parsear indicando los '/'
moment(start, 'YYYY/MM/DD').toDate() //2020/07/13 :)