Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // app.config.ts
- import {OpaqueToken} from 'angular2/core';
- export let APP_CONFIG = new OpaqueToken('app.config');
- export interface Config {
- apiEndpoint: string,
- title: string
- }
- export const CONFIG:Config = {
- apiEndpoint: 'api.heroes.com',
- title: 'Dependency Injection'
- };
- // app.component.ts
- import {Component, Inject, provide} from 'angular2/core';
- import {APP_CONFIG, Config, CONFIG} from './app.config';
- @Component({
- selector: 'my-app',
- template: `
- <h1> {{title}} </h1>
- `,
- providers: [
- provide(APP_CONFIG, {useValue: CONFIG})
- ]
- })
- export class AppComponent implements NgOnInit {
- title:string;
- constructor( @Inject(APP_CONFIG) config:Config ) {
- this.title = config.title;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment