How do I import javascript files as modules in Angular 2?
Right now in my system config I have:
System.config({
paths: {
lodash: '../../node_modules/lodash/index.js',
constants: 'app/constants.js'
},
I have a file constants.js which is:
import {Injectable} from 'angular2/core';
@Injectable()
export class Constants{
api_dir: string;
constructor(){
var prod = false;
if (prod){
this.root_dir = 'http://google.com/'
} else{
this.root_dir = 'http://localhost/'
}
this.api_dir = this.root_dir + 'api/'
}
}
In one of my components I have:
import {Constants} from 'constants';
Which gives me the error:
Cannot find module 'constants'
How do I turn a javascript file into a module so I can always import it without giving the relative path to it?