Skip to content

Instantly share code, notes, and snippets.

View ricmello's full-sized avatar
🏠
Working from home

Ricardo Mello ricmello

🏠
Working from home
View GitHub Profile
{
"$schema": "http://json-schema.org/schema",
"id": "my-schematics",
"type": "object",
"properties": {
"path": {
"description": "The path to create the module.",
"type": "string",
"format": "path",
"visible": false
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"extends": ["@schematics/angular"],
"schematics": {
"my-schematics": {
"description": "A custom module generator.",
"factory": "./my-schematics/index#mySchematics",
"schema": "./my-schematics/schema.json"
}
}
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
// You don't have to export the function as default. You can also have more than one rule factory
// per file.
export function mySchematics(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
tree.create(_options.name || 'hello', 'world');
return tree;
};
}
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
// You don't have to export the function as default. You can also have more than one rule factory
// per file.
export function mySchematics(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
return tree;
};
}
@ricmello
ricmello / collection.json
Last active June 11, 2019 05:00
Create your first schematics
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"my-schematics": {
"description": "A blank schematic.",
"factory": "./my-schematics/index#mySchematics"
}
}
}
public getAutoCompleteResult(term: string) {
return this.httpClient
.hideLoader()
.get(`http://my-domain/api/autocomplete`);
}
providers: [
{ provide: HttpClient, useClass: HttpService },
],
@Injectable()
export class HttpService extends HttpClient {
constructor(private httpHandler: HttpHandler,
private injector: Injector,
@Optional() @Inject(HTTP_DYNAMIC_INTERCEPTORS) private interceptors: HttpInterceptor[] = []) {
super(httpHandler);
if (!this.interceptors) {
// Configure default interceptors that can be disabled here
import { InjectionToken } from '@angular/core';
import { HttpClient, HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
declare module '@angular/common/http/src/client' {
export interface HttpClient {
hideLoader(hide?: boolean): HttpClient;
}
declare module '@angular/common/http/src/client' {
export interface HttpClient {
hideLoader(hide?: boolean): HttpClient;
}
}