无法导入toastr模块

无法导入toastr模块

本文介绍了无法导入toastr模块,2角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个角2应用程序与版本2.0.0-alpha.46,我试图导入toastr模块。

I am creating an Angular 2 application with version 2.0.0-alpha.46 and I trying to import the toastr module.

我已经下载了图书馆,还下载了绝对类型的文件中。

I have downloaded the library and also downloaded the definitely typed file as well.

在我的html页面,我添加了一个<脚本> 的.js文件标记:

In my html page, I add a <script> tag for the .js file:

<script src="./src/libs/toastr/toastr.min.js"></script>

在Visual Studio中code,我尝试导入模块,像这样:

In Visual Studio Code, I try to import the module like so:

import * as toastr from 'toastr';

我就能够在我的组件toastr.info(信息)来调用 - 我甚至获得智能;然而,当我真正尝试加载网页,我收到了404 / src目录/ toastr没有发现错误。

I am then able to call toastr.info('message') in my component - I even get intellisense; However, when i actually try to load the webpage I get a 404 /src/toastr not found error.

如果我试图让明确一些寻找toastr肯定输入文件:

If I try to get explicit about finding the toastr definitely typed file:

import * as toastr from '../../definitions/toastr/toastr';

我会得到[完整路径TS模块]不是一个模块。

I will get "[full path to ts module] is not a module."

我也尝试添加 ///&lt;参考路径=../../ toastr.d.ts/&GT; 来的顶部文件我使用的模块导入无济于事。

I have also tried adding ///<reference path="../../toastr.d.ts" /> to the top of the file I am using to import the module to no avail.

有没有人有什么可能会发生一个想法?我画什么我可能有错误的一项空白。提前致谢。

Does anyone have an idea of what may be happening? I am drawing a blank on what I may have wrong. Thanks in advance.

推荐答案

我觉得 toastr.min.js 文件不包含一个模块都没有。我的理解是打字稿定义文件有助于定义由toastr库使用的方法和结构。这是你的IDE为code完成内很有帮助。这个定义文件没有真正创建一个模块,可以在运行时使用...

I think that the toastr.min.js file doesn't contain a module at all. My understanding is that TypeScript definition files help you to define the methods and structures used by the toastr library. This is helpful within your IDE for code completion. This definition file doesn't actually create a module that can be use at runtime...

这意味着你可以直接直接使用 toastr 对象,而无需将其导入这样的:进口*从'toastr ... ';

This means that you can use directly the toastr object directly without having to import it like this: import * as toastr from '...';.

下面是相应的plunkr:<一href=\"https://plnkr.co/edit/wzdoisKBrZYTeSX8r7Nd?p=$p$pview\">https://plnkr.co/edit/wzdoisKBrZYTeSX8r7Nd?p=$p$pview.

Here is the corresponding plunkr: https://plnkr.co/edit/wzdoisKBrZYTeSX8r7Nd?p=preview.

希望是有道理的。
蒂埃里

Hope that makes sense.Thierry

这篇关于无法导入toastr模块,2角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:17