【发布时间】:2017-07-25 12:32:26
【问题描述】:
我正在尝试将 ng2-file-upload 模块集成到我的应用程序中。
我收到此模板错误:无法绑定到“上传器”,因为它不是“输入”的已知属性
更新文件夹 str:
/src/app/app.module.ts
/src/app/components/layout/
layout.module.ts
other layout components files
/category-items
category-items.module.ts
category-items.component.ts
在 layout.module.ts 中
import { LayoutComponent } from './layout.component';
declarations: [
LayoutComponent,
在 category-items.module.ts 中
import { CategoryItemsComponent } from './category-items.component';
import {FileUploadModule} from "ng2-file-upload";
imports: [ ...FileUploadModule ... ]
app\app.module.ts
import {FileUploadModule} from "ng2-file-upload";
imports: [ ...FileUploadModule ... ]
app\components\layout\category-items\category-items.component.ts
import { FileUploader } from 'ng2-file-upload';
@Component({
selector: 'button-view',
template: `
<input type="file" class="form-control" name="single" ng2FileSelect [uploader]="uploader" />
`
})
export class ButtonViewComponent implements ViewCell, OnInit {
...
public uploader:FileUploader = new FileUploader({url:'http://lcoalhost:5000/upload'});
}
@Component({
selector: 'app-category-items',
templateUrl: './category-items.component.html',
styleUrls: ['./category-items.component.scss']
})
export class CategoryItemsComponent implements OnInit {
...
}
或者如果我尝试如下:我得到意外的关闭 div 标签
<div ng2FileDrop
(fileOver)-'fileOverBase($event)'
[uploader]="uploader"
class="well my-drop-zone">
Base drop zone
</div>
我在各种帖子的 app.module 中为 'FileUploadModule' 尝试了多种导入组合,但在我的情况下似乎都没有。
错误堆栈跟踪:
“未捕获(承诺中):错误:模板解析错误:↵无法绑定到“上传器”,因为它不是“输入”的已知属性。(“↵ ↵
已经在谷歌上搜索了许多帖子以寻找相同的解决方案:
一些参考是:(但没有帮助)
https://github.com/valor-software/ng2-file-upload/issues/418
https://github.com/valor-software/ng2-file-upload/issues/608
【问题讨论】:
-
您是否在与
CategoryItemsComponent相同的模块中导入了FileUploadModule?即:CategoryItemsComponent是否在 app.module.ts 中声明only? -
已更新我的文件夹 str,您能告诉我缺少什么或我应该验证什么吗?
-
我怀疑你没有将模块导入正确的模块 - category-items.module.ts 你能粘贴它以便我验证
-
哦,伙计,我明白了...感谢其余部分,我必须在 category-items.module.ts 下导入 FileUploadModule
-
我会将其添加为未来用户的答案