【问题标题】:Angular 2 system-config.ts doesn't seem to be working with my app specific barrelsAngular 2 system-config.ts 似乎不适用于我的应用程序特定桶
【发布时间】:2016-08-03 21:30:10
【问题描述】:

这是我的 system-config.ts:

'use strict';

// SystemJS configuration file, see links for more information
// https://github.com/systemjs/systemjs
// https://github.com/systemjs/systemjs/blob/master/docs/config-api.md

/***********************************************************************************************
 * User Configuration.
 **********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
  'moment': 'vendor/moment/moment.js',
  'ng2-bootstrap': 'vendor/ng2-bootstrap'
};

/** User packages configuration. */
const packages: any = {
  'moment': {
    format: 'cjs'
  },
  'ng2-bootstrap': {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'ng2-bootstrap.js'
  }
};

////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
 * Everything underneath this line is managed by the CLI.
 **********************************************************************************************/
const barrels: string[] = [
  // Angular specific barrels.
  '@angular/core',
  '@angular/common',
  '@angular/compiler',
  '@angular/forms',
  '@angular/http',
  '@angular/router',
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',

  // Thirdparty barrels.
  'rxjs',

  // App specific barrels.
  'app',
  'app/shared',
  'app/photos'
  /** @cli-barrel */
];

const cliSystemConfigPackages: any = {};
barrels.forEach((barrelName: string) => {
  cliSystemConfigPackages[barrelName] = { main: 'index' };
});

/** Type declaration for ambient System. */
declare var System: any;

// Apply the CLI SystemJS configuration.
System.config({
  map: {
    '@angular': 'vendor/@angular',
    'rxjs': 'vendor/rxjs',
    'main': 'main.js'
  },
  packages: cliSystemConfigPackages
});

// Apply the user's configuration.
System.config({ map, packages });

我可以导入所有模块,除了应用程序特定的桶。

所以,import { AlertComponent } from 'ng2-bootstrap/ng2-bootstrap'; 工作正常。

但是,import { PhotoService } from 'app/shared'; 没有。

我正在正确导出,因为如果我这样做 import { PhotoService } from '../../shared'; 它可以工作。

有人可以帮帮我吗?我做错了什么?

【问题讨论】:

    标签: angularjs typescript angular angular-cli


    【解决方案1】:

    需要是相对路径。

    import { PhotoService } from './app/shared';
    

    这就是../../* 起作用的原因。与系统无关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-10
      • 2018-06-10
      • 2020-04-12
      相关资源
      最近更新 更多