无法在Angular2中使用外部依赖项

无法在Angular2中使用外部依赖项

本文介绍了无法在Angular2中使用外部依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用创建了Angular2项目,但是当我尝试安装外部依赖关系,编译器不会将文件夹从node_modules移动到dist / vendor。

I've created an Angular2 project with Angular-CLI but when I try to install external dependencies the compiler doesn't move the folder from node_modules to dist/vendor.

这就是我所做的:

$ npm install --save angular2-google-maps
$ ng serve

我的组件文件:

import {Component} from 'angular2/core';
import {ANGULAR2_GOOGLE_MAPS_DIRECTIVES} from 'angular2-google-maps/core';

@Component({
  selector: 'contact',
  templateUrl: 'app/components/contact/contact.html',
  styleUrls: ['app/components/contact/contact.css'],
  providers: [],
  directives: [ANGULAR2_GOOGLE_MAPS_DIRECTIVES],
  pipes: []
})
export class Contact {
  lat: number = 51.678418;
  lng: number = 7.809007;
  constructor() {}
}

当我运行 ng服务并转到网络浏览器,我将收到以下错误:

when I run ng serve and go to the web browser I get the following error:


推荐答案

我遇到了同样的问题,并将以下行添加到在system-config.ts中配置软件包:

I had the same issue and solved it by adding the following line to the packages configuration in system-config.ts:

/** User packages configuration. */
const packages: any = {
    'angular2-google-maps': { defaultExtension: 'js' }
};

这篇关于无法在Angular2中使用外部依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:47