Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "ZoneAwareError.__zone_symbol__error (SystemJS) Unexpected value 'Http' imported by the module 'AppModule'
- Error: Unexpected value 'Http' imported by the module 'AppModule'
- at SyntaxError.ZoneAwareError (http://localhost:3000/node_modules/zone.js/dist/zone.js:811:33)
- at SyntaxError.BaseError [as constructor] (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1592:20)
- at new SyntaxError (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1795:20)
- at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:18301:48)
- at Array.forEach (native)
- at CompileMetadataResolver.getNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:18286:53)
- at JitCompiler._loadModules (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27360:68)
- at JitCompiler._compileModuleAndComponents (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27320:56)
- at JitCompiler.compileModuleAsync (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27286:25)
- at PlatformRef_._bootstrapModuleWithZone (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8081:29)
- at PlatformRef_.bootstrapModule (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8056:25)
- at Object.eval (http://localhost:3000/app/main.js:4:53)
- at eval (http://localhost:3000/app/main.js:6:4)
- at eval (http://localhost:3000/app/main.js:7:3)
- at eval (<anonymous>)
- Evaluating http://localhost:3000/app/main.js
- Error loading http://localhost:3000/app/main.js"
- function initConfig(config: AppConfig){
- return () => config.load()
- }
- @NgModule({
- imports: [ BrowserModule, FormsModule, ReactiveFormsModule],
- declarations: [ AppComponent ],
- bootstrap: [ AppComponent ],
- providers: [HttpModule, AppConfig, { provide: APP_INITIALIZER, useFactory: initConfig, deps: [AppConfig], multi: true }]
- })
- export class AppModule { }
- @Injectable()
- export class AppConfig {
- private config: Object = null;
- private env: Object = null;
- constructor(private http: Http) {
- }
- /**
- * Use to get the data found in the second file (config file)
- */
- public getConfig(key: any) {
- return this.config[key];
- }
- /**
- * Use to get the data found in the first file (env file)
- */
- public getEnv(key: any) {
- return this.env[key];
- }
- /**
- * a) Loads "env.json" to get the current working environment (e.g.: 'production', 'development')
- * b) Loads "config.[env].json" to get all env's variables (e.g.: 'config.development.json')
- */
- public load() {
- return new Promise((resolve, reject) => {
- this.http.get('./app/conf/env.json').map( res => res.json() ).catch((error: any):any => {
- console.log('Configuration file "env.json" could not be read');
- resolve(true);
- return Observable.throw(error.json().error || 'Server error');
- }).subscribe( (envResponse) => {
- this.env = envResponse;
- let request:any = null;
- switch (envResponse["env"]) {
- case 'production': {
- request = this.http.get('app/conf/config.' + envResponse["env"] + '.json');
- } break;
- case 'development': {
- request = this.http.get('app/conf/config.' + envResponse["env"] + '.json');
- } break;
- case 'default': {
- console.error('Environment file is not set or invalid');
- resolve(true);
- } break;
- }
- if (request) {
- request
- .map( res => res.json() )
- .catch((error: any) => {
- console.error('Error reading ' + envResponse["env"] + ' configuration file');
- resolve(error);
- return Observable.throw(error.json().error || 'Server error');
- })
- .subscribe((responseData) => {
- debugger;
- this.config = responseData;
- resolve(true);
- });
- } else {
- console.error('Env config file "env.json" is not valid');
- resolve(true);
- }
- });
- });
- }
- }
- @Injectable()
- export class AnyClass {
- constructor(private http: Http, private config: AppConfig) {
- this.config = config;
- }
- ...
- let host:string = this.config.getConfig('host');
- {
- "name": "angular-quickstart",
- "version": "1.0.0",
- "description": "QuickStart package.json from the documentation, supplemented with testing support",
- "scripts": {
- "build": "tsc -p app/",
- "build:watch": "tsc -p app/ -w",
- "build:e2e": "tsc -p e2e/",
- "serve": "lite-server -c=bs-config.json",
- "serve:e2e": "lite-server -c=bs-config.e2e.json",
- "prestart": "npm run build",
- "start": "concurrently "npm run build:watch" "npm run serve"",
- "pree2e": "npm run build:e2e",
- "e2e": "concurrently "npm run serve:e2e" "npm run protractor" --kill-others --success first",
- "preprotractor": "webdriver-manager update",
- "protractor": "protractor protractor.config.js",
- "pretest": "npm run build",
- "test": "concurrently "npm run build:watch" "karma start karma.conf.js"",
- "pretest:once": "npm run build",
- "test:once": "karma start karma.conf.js --single-run",
- "lint": "tslint ./app/**/*.ts -t verbose"
- },
- "keywords": [],
- "author": "",
- "license": "MIT",
- "dependencies": {
- "@angular/common": "~2.4.0",
- "@angular/compiler": "~2.4.0",
- "@angular/core": "~2.4.0",
- "@angular/forms": "~2.4.0",
- "@angular/http": "~2.4.0",
- "@angular/platform-browser": "~2.4.0",
- "@angular/platform-browser-dynamic": "~2.4.0",
- "@angular/router": "~3.4.0",
- "bootstrap": "^3.3.7",
- "angular-in-memory-web-api": "~0.2.4",
- "systemjs": "0.19.40",
- "core-js": "^2.4.1",
- "rxjs": "5.0.1",
- "reflect-metadata": "^0.1.9",
- "zone.js": "^0.7.4"
- },
- "devDependencies": {
- "concurrently": "^3.2.0",
- "lite-server": "^2.2.2",
- "typescript": "~2.0.10",
- "canonical-path": "0.0.2",
- "tslint": "^3.15.1",
- "lodash": "^4.16.4",
- "jasmine-core": "~2.4.1",
- "karma": "^1.3.0",
- "karma-chrome-launcher": "^2.0.0",
- "karma-cli": "^1.0.1",
- "karma-jasmine": "^1.0.2",
- "karma-jasmine-html-reporter": "^0.2.2",
- "protractor": "~4.0.14",
- "rimraf": "^2.5.4",
- "@types/node": "^6.0.46",
- "@types/jasmine": "2.5.36"
- },
- "repository": {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement