angular 5-ng2文件上载:无法绑定到“uploader”,因为它不是“div”的已知属性
我读了前面的问题,答案的答案已经准备好了,这就是为什么我开始另一个问题 我在Angular 5中上传ng2文件时遇到以下错误:angular 5-ng2文件上载:无法绑定到“uploader”,因为它不是“div”的已知属性,angular,ng-file-upload,angular5,angular-template,Angular,Ng File Upload,Angular5,Angular Template,我读了前面的问题,答案的答案已经准备好了,这就是为什么我开始另一个问题 我在Angular 5中上传ng2文件时遇到以下错误: Uncaught Error: Template parse errors: Can't bind to 'uploader' since it isn't a known property of 'div'. ("s': hasAnotherDropZoneOver}" (fileOver)="fileOverAnother(
Uncaught Error: Template parse errors:
Can't bind to 'uploader' since it isn't a known property of 'div'. ("s': hasAnotherDropZoneOver}"
(fileOver)="fileOverAnother($event)"
[ERROR ->][uploader]="uploader"
class="well my-drop-zone">
Another drop zone
"): ng:///AppModule/UploadComponent.html@25:17
at syntaxError (compiler.js:466)
at TemplateParser.parse (compiler.js:24312)
at JitCompiler._parseTemplate (compiler.js:33699)
at JitCompiler._compileTemplate (compiler.js:33674)
at eval (compiler.js:33576)
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:33576)
at eval (compiler.js:33446)
at Object.then (compiler.js:455)
at JitCompiler._compileModuleAndComponents (compiler.js:33445)
我将该指令导入并声明到我的app.module.ts中,错误依然存在。是否有人在ng file upload和angular 5中遇到此问题?需要导入FileUploadModule,并将其添加到声明组件的模块中的导入中
import { FileUploadModule } from "ng2-file-upload"; //Should import HERE
imports: [ ...FileUploadModule ... ] //RIGHT PLACE
在相应的module.ts文件中添加
在此class.ts文件中,添加条目
在HTML文件中添加选择按钮
您的主@NgModule中是否有模式:[自定义元素\u模式]?@msanford是的,我有。我真的弄明白了。见下面的答案。但它不会让我把它标记为已回答。我贴出来后就明白了。太好了!是的,你必须在几天后回来接受它,但请在计时器过期后再接受。@msanford。谢谢你的帮助!您是否将其从参数绑定更改为事件绑定?这真的有效吗?我对ng uploader一无所知,但这对我来说似乎太奇怪了,因为这两件事显然是朝着相反的方向工作的。知道核心问题是什么吗?嗯?属性绑定到事件绑定是否适合您?
import { FileUploadModule } from 'ng2-file-upload';
Add it under import
@NgModule({
imports: [
FileUploadModule
]
})
<b>Import FileUploaderOptions,FileUploader into your .ts file </b>
import { FileUploaderOptions,FileUploader } from 'ng2-file-upload';
options: FileUploaderOptions;
uploader: FileUploader = new FileUploader(this.options);
<b>In the ngOnInit() add the text </b>
this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {
console.log('file:uploaded:', item, status, response);
alert('File uploaded successfully');
}
<div>
<input type="file" name="photo" ng2FileSelect [uploader]="uploader" />
<button type="button" class="btn btn-success btn-s"
(click)="uploader.uploadAll()"
[disabled]="!uploader.getNotUploadedItems().length" >
Upload file
</button>
</div>