Skip to content

Instantly share code, notes, and snippets.

@endam
Created April 29, 2019 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endam/65154d4c056bd5197c19f47ee4ebed3c to your computer and use it in GitHub Desktop.
Save endam/65154d4c056bd5197c19f47ee4ebed3c to your computer and use it in GitHub Desktop.
Dep in Angular
import { NgModule } from '@angular/core';
import 'reflect-metadata';
export class DepManager {
static requiredProps = ['declarations', 'imports'];
static setDeps(component: Object, deps: NgModule): void {
Reflect.defineMetadata('deps', deps, component);
}
static getDeps(component: Object): NgModule {
let deps = Reflect.getMetadata('deps', component);
deps = deps || {};
for (const prop of DepManager.requiredProps) {
if (!deps.hasOwnProperty(prop)) {
deps[prop] = new Array();
}
}
return deps;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment