npm.io
0.0.8 • Published 6 years ago

@steveylin/ng2-configure

Licence
MIT
Version
0.0.8
Deps
0
Size
144 kB
Vulns
0
Weekly
0

Steve Y Lin logo

Steve Y Lin

Powerful full stack library for faster and easier development.
@steveylin/ng2-configure

Report bug · Request feature

Table of contents

Usage

Install package
npm i @steveylin/ng2-configure --save
Add into module to preload configure file

For example

File: app.module.ts

...
import { ConfigureModule, ConfigureLoader } from '@steveylin/ng2-configure';

/**
 * Main App Module
 */
@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    // Use 'forRoot' to preload configure file you want
    ConfigureModule.forRoot(
      {
        key: 'datasources',
        path: './../assets/configs/datasources.json'
      }
    ),
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

File: app.component.ts

...
import { ConfigureLoader } from '@steveylin-libs/configure';

/**
 * Main App Component
 */
@Component({
  selector: 'steveylin-libs-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less']
})
export class AppComponent implements OnInit {

  /**
   * @param configureLoader Configure load files service
   */
  constructor(private configureLoader: ConfigureLoader) {}

  /**
   * Initilailize component
   *
   * @method public
   */
  public ngOnInit(): void {
    const config = this.configureLoader.get<AppConfig>('datasources');
    console.log(config.mqtt);
  }

}
Preview

Status

npm version type

Code and documentation copyright 2020 Steve Y Lin.

Keywords