Angular 2:无法绑定到 'uploader',因为它不是 'input' 的已知 属性
Angular 2: Can't bind to 'uploader' since it isn't a known property of 'input'
我正在尝试将 ng2-file-upload 模块集成到我的应用程序中。
我收到此模板错误:无法绑定到 'uploader',因为它不是 'input'
的已知 属性
更新文件夹 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,
类别-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' 的多种导入组合,但 none 似乎在我的案例.
错误堆栈跟踪:
"Uncaught (in promise): Error: Template parse errors:↵Can't bind to 'uploader' since it isn't a known property of 'input'. ("↵ ↵
在 google 上搜索了很多帖子以寻找相同的解决方案:
一些参考资料是:(但 none 有帮助)
https://github.com/valor-software/ng2-file-upload/issues/418
https://github.com/valor-software/ng2-file-upload/issues/608
您需要在使用 'upload'
声明组件的模块中导入 FileUploadModule
,在您的情况下为 category-items.module.ts
类别-items.module.ts
import { CategoryItemsComponent } from './category-items.component';
import { FileUploadModule } from "ng2-file-upload"; //Should import HERE
imports: [ ...FileUploadModule ... ] //RIGHT PLACE
添加到app.module.ts这个
import { FileSelectDirective } from 'ng2-file-upload';
@NgModule({
imports: [
...
],
declarations: [
FileSelectDirective
],
providers: [
...
],
bootstrap: [
App,
],
})
https://github.com/valor-software/ng2-file-upload/issues/418#issuecomment-249865170
或者尝试将 FIleUploadModule 导入每个父模块
从 'ng2-file-upload' 导入 { FIleUploadModule };
imports: [
FIleUploadModule,
..........,
........,
......,
]
应该可以。
我正在尝试将 ng2-file-upload 模块集成到我的应用程序中。
我收到此模板错误:无法绑定到 'uploader',因为它不是 'input'
的已知 属性更新文件夹 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,
类别-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' 的多种导入组合,但 none 似乎在我的案例.
错误堆栈跟踪:
"Uncaught (in promise): Error: Template parse errors:↵Can't bind to 'uploader' since it isn't a known property of 'input'. ("↵ ↵
在 google 上搜索了很多帖子以寻找相同的解决方案:
一些参考资料是:(但 none 有帮助)
https://github.com/valor-software/ng2-file-upload/issues/418
https://github.com/valor-software/ng2-file-upload/issues/608
您需要在使用 'upload'
声明组件的模块中导入 FileUploadModule
,在您的情况下为 category-items.module.ts
类别-items.module.ts
import { CategoryItemsComponent } from './category-items.component';
import { FileUploadModule } from "ng2-file-upload"; //Should import HERE
imports: [ ...FileUploadModule ... ] //RIGHT PLACE
添加到app.module.ts这个
import { FileSelectDirective } from 'ng2-file-upload';
@NgModule({
imports: [
...
],
declarations: [
FileSelectDirective
],
providers: [
...
],
bootstrap: [
App,
],
})
https://github.com/valor-software/ng2-file-upload/issues/418#issuecomment-249865170
或者尝试将 FIleUploadModule 导入每个父模块
从 'ng2-file-upload' 导入 { FIleUploadModule };
imports: [
FIleUploadModule,
..........,
........,
......,
]
应该可以。