本文介绍了如何导入在同一名称空间上扩展另一个模块的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 简单的路障。我需要在我的一些服务中使用Leaflet和Leaflet-Draw插件。 我不知道如何导入完整的模块(核心和插件) //核心导入*作为来自'传单'的L; //扩展名 import'leaflet-draw'; 导出类LeafletConsumerService {} 我有一个解决方案我不喜欢好像很多。我通过在 index.html 中硬链接来加载库,消费者只需要对打包文件进行引用声明 ///< reference path =../ typings / index.d.ts/> 导出类LeafletConsumerService {} 我还有其他办法吗这个?有没有办法导入一个文件,只会导致副作用到已经加载的模块?解决方案好的,一个快速而肮脏的解决方如果您从快速入门回购启动项目,则此答案有效。转到 system.config.extras.js 并扩展您的配置: System.config({ map:{'leaflet':'npm:leaflet / dist / leaflet.js'},包裹:{宣传单:{ defaultExtension:'js'},} }); 这意味着我们现在可以导入传单 从'leaflet'导入*为L; 并按照描述添加我们相应的扩展文件 import'your-leaflet-extension'; 请记住扩展您的分机的类型信息(通过打字文件或自己制作) A simple road block. I need to use Leaflet and the Leaflet-Draw plugin in some of my services.I don't know how to import the complete module (core and plugin)// the coreimport * as L from 'leaflet';// extensionimport 'leaflet-draw';export class LeafletConsumerService {}I have a solution that I don't like much. I load the libraries by hard-linking them in index.html and the consumer simply has a reference declaration to the typings files/// <reference path="../typings/index.d.ts" />export class LeafletConsumerService {}Is there no other way I can do this? is there a way to import one file that should just cause a side-effect onto an already loaded module? 解决方案 Ok, a quick and dirty solution. This answer works if you start your project from a quickstart repo. Goto system.config.extras.js and extend your configuration as such:System.config({ map: { 'leaflet': 'npm:leaflet/dist/leaflet.js' }, packages: { leaflet: { defaultExtension: 'js' }, }});this means that we can now import leaflet as suchimport * as L from 'leaflet';and add our corresponding extension files as describedimport 'your-leaflet-extension';Remember to extend the type info for your extensions (through a typings file or make your own) 这篇关于如何导入在同一名称空间上扩展另一个模块的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 07:34