【问题标题】:how to use angular 2 file uploaf in ES5?如何在 ES5 中使用 Angular 2 文件上传?
【发布时间】:2017-08-25 18:11:00
【问题描述】:

我尝试使用 Angular 2 文件上传,但它仅针对 TypeScript 进行了解释,并且我使用的是 ES5

我该怎么办?

我使用这个库: https://github.com/valor-software/ng2-file-upload

我知道 Angular 2 可以用 ES5 编写,并且我已经使用 Angular 2 和 Material 2 在 ES5 中编写了应用程序

【问题讨论】:

  • 如果你已经用 ES5 写过应用程序,那有什么问题?
  • 在 ng.core 或 ng.common 等全局空间中找不到它的模块或指令等,也不知道在模块定义中添加内容的位置。
  • 我会尽力提供帮助的。似乎 plunker 不起作用

标签: angular


【解决方案1】:

要在 es5 中使用 ng2-file-upload 包,您可以使用 umd 包

https://unpkg.com/ng2-file-upload@1.2.0/bundles/ng2-file-upload.umd.js

如果你打开它,你会注意到

root["ng2-file-upload.umd"] = factory(root["@angular/core"], root["@angular/common"]);

因此,在没有任何加载器的情况下加载此脚本之前,您必须执行以下操作:

window["@angular/core"] = ng.core;
window["@angular/common"] = ng.common;

那么您可以通过以下方式获得对FileUploadModule模块和其他类的引用:

var FileUploadModule = window['ng2-file-upload.umd'].FileUploadModule;

JsFiddle Example Angular2 v4.0.1 es5 nf2-file-upload

【讨论】:

  • 这么好的解释
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-02
  • 2017-07-04
  • 2016-10-14
  • 2017-11-02
  • 2017-12-28
  • 2023-03-11
  • 2016-05-20
相关资源
最近更新 更多