【发布时间】:2016-11-13 09:17:50
【问题描述】:
为什么这个上传文件表单示例在Index.html 中有效,而在任何component.html 文件中都无效?
如果我将它移动到任何 component.html 单击添加文件甚至不会打开浏览对话框。
<form id="upload" method="post" action="upload.php" enctype="multipart/form-data">
<div id="drop">
<a>Add File</a> Drag and Drop
<input type="file" name="upl" />
</div>
<ul id="uploadList"></ul>
</form>
编辑:我必须提一下,我只在Index.html 中导入js 文件,我也没有在System.js 或angular-cli.build.js 中导入
在 Index.html 中的引用之一是:
<script src="assets/js/uploadScript.js"></script>
这是来自uploadScript.js 的代码,应该会打开浏览器对话框:
$('#drop a').click(function(){
$(this).parent().find('input').click();
});
【问题讨论】:
-
我更惊讶的是,Add File 链接对您有用,会打开对话框。您确定吗?对我来说,它适用于组件和 index.html,但我必须点击输入..在 Chrome 和 IE 中测试
-
是的,它在 Index.html 中工作。我从一个旧项目中导入了文件并尝试实现 angular2 组件。看看我的编辑。也许这就是原因?
-
好吧,那么在您的 javascript 文件中,必须有某个地方可以处理“添加文件”链接并使其工作..在第一个答案stackoverflow.com/questions/10216331/… 中类似这里的东西尝试找到该代码并在这里发布
-
再次编辑。我发布了我认为打开对话框的代码。但是,如果它是在 Index.html 中导入的,那是否会自动在所有 Angular2 组件中使用而无需在 system.js 中导入它们?