简体   繁体   English

未捕获(承诺):错误:模板解析错误:由于它不是“输入”的已知属性,因此无法绑定到“上载器”

[英]Uncaught (in promise): Error: Template parse errors: Can't bind to 'uploader' since it isn't a known property of 'input'

Ajouter-produit.component.ts Ajouter-produit.component.ts

    import { Component, OnInit, ElementRef, ViewChild }
    from '@angular/core';
    import { FormGroup, FormControl } from '@angular/forms';
    import { Produit } from 'src/app/interface/produit';
    import { ProduitService } from 'src/app/service/produit.service';
    import { ActivatedRoute } from '@angular/router';
    import { MatSnackBar } from '@angular/material';
    import {FileUploader} from 'ng2-file-upload';
    @Component({
    selector: 'app-ajouter-produit',
    templateUrl: './ajouter-produit.component.html',
    styleUrls: ['./ajouter-produit.component.scss'],
    })
    export class AjouterProduitComponent implements OnInit {
    produitForm = new FormGroup({
    nomProduit: new FormControl(''),
    duree: new FormControl(''),
    });
    produit: Produit;
    idProduit: number;
    /* PHOTO  */
    @ViewChild('fileInput') fileInput: ElementRef;
    uploader: FileUploader;
    isDropOver: boolean;
    /*     */
    constructor( private produitService: ProduitService, private route: 
    ActivatedRoute, public snackBar: MatSnackBar) { }
    ngOnInit(): void {
    const headers = [{name: 'Accept', value: 'application/json'}];
    this.uploader = new FileUploader({url: 
    'http://localhost:9090/api/auth/produits/files', autoUpload: true, 
    headers: headers});
    this.uploader.onCompleteAll = () => console.log(this.uploader);
    }
    saveProduit() {
    if (this.produitForm.valid) {
    console.log('user==============', this.produitForm.value);
    if (this.produit === undefined) {
    this.produitService.saveproduit(this.produitForm.value).subscribe( 
    produit =>
    this.snackBar.open('Produit ajouté!', '×', { panelClass: 'success', 
    verticalPosition: 'top', duration: 3000 }),
    err =>
          console.log('ERROOr=$====', err)
        );
      }

    }

    } 
    fileOverAnother(e: any): void {
    this.isDropOver = e;

    }

    fileClicked() {
    this.fileInput.nativeElement.click();
    } 
    }

ajouter-produit.html ajouter-produit.html

    enter code <div fxLayout="row wrap">
    <div fxFlex="100" fxFlex.gt-sm="50" class="p-2">
      <h2 class="text-muted text-center">Ajouter un produit</h2>
      <form [formGroup]="produitForm">
          <mat-form-field class="w-100 mt-2">
              <input matInput placeholder="Nom du produit" 
    formControlName="nomProduit"  required>
             </mat-form-field>
          <mat-form-field class="w-100 mt-1">
              <input matInput placeholder="Duree" formControlName="duree" required>
          </mat-form-field>
          <div class="text-center mt-2">
            <input #fileInput type="file" ng2FileSelect [uploader]="uploader"/>

            <button  ng2FileDrop
                 [ngClass]="{'dragover': isDropOver}"
                 [uploader]="uploader"
                 (fileOver)="fileOverAnother($event)"
                 (click)="fileClicked()">  choisir une image
            </button>
              <button mat-raised-button color="primary"  (click)="saveProduit()">Save</button>
          </div> 
      </form>
      </div>
      <div fxFlex="100" fxFlex.gt-sm="50" class="p-2" ngClass.sm="mt-2" 
      ngClass.xs="mt-2">

      </div>
      </div> 

app.module.ts app.module.ts

    ...import {FileUploadModule, FileSelectDirective, FileDropDirective} from 
    'ng2-file-upload';
    @NgModule({
    imports: [
    BrowserModule,
    BrowserAnimationsModule,
    HttpClientModule,
    NgxSpinnerModule,
    AgmCoreModule.forRoot({
      apiKey: 'AIzaSyAAYi6itRZ0rPgI76O3I83BhhzZHIgMwPg'
    }),
    SharedModule,
    FileUploadModule,
    routing
    ],
    declarations: [
    AppComponent,
    PagesComponent,
    NotFoundComponent,
    TopMenuComponent,
    MenuComponent,
    SidenavMenuComponent,
    BreadcrumbComponent,
    OptionsComponent,
    FooterComponent,
    MyhomeComponent,
    ],
    providers: [
    UserService,
    AuthenticationService,
    TokenStorageService,
    AppSettings,
    AuthGuard,
    AppService,
    { provide: OverlayContainer, useClass: CustomOverlayContainer },
    { provide: MAT_MENU_SCROLL_STRATEGY, useFactory: menuScrollStrategy, 
    deps: [Overlay] },
    { provide: HTTP_INTERCEPTORS, useClass: AppInterceptor, multi: true }
    ],
    bootstrap: [AppComponent] 
    })
    export class AppModule { }    

Uncaught (in promise): Error: Template parse errors: Can't bind to 'uploader' since it isn't a known property of 'input'. 未被捕获(承诺):错误:模板解析错误:无法绑定到“上载器”,因为它不是“输入”的已知属性。 (" (“

enter code  <div class="text-center mt-2">
        <input #fileInput type="file" ng2FileSelect [ERROR ->] 
[uploader]="uploader"/>
        <button  ng2FileDrop
"): ng:///AdminModule/AjouterProduitComponent.html@12:56
Can't bind to 'uploader' since it isn't a known property of 'button'. ("      
<button  ng2FileDrop
             [ngClass]="{'dragover': isDropOver}"
             [ERROR ->][uploader]="uploader"
             (fileOver)="fileOverAnother($event)"
             (click"): 
 ng:///AdminModule/AjouterProduitComponent.html@16:17
 Error: Template parse errors:
 Can't bind to 'uploader' since it isn't a known property of 'input'. ("
       <div class="text-center mt-2">
        <input #fileInput type="file" ng2FileSelect [ERROR ->] 
 [uploader]="uploader"/>
        <button  ng2FileDrop
  "): ng:///AdminModule/AjouterProduitComponent.html@12:56
  Can't bind to 'uploader' since it isn't a known property of 'button'. 
  ("      <button  ng2FileDrop
             [ngClass]="{'dragover': isDropOver}"
             [ERROR ->][uploader]="uploader"
             (fileOver)="fileOverAnother($event)"
             (click"): 
   ng:///AdminModule/AjouterProduitComponent.html@16:17 

the UploadFileModule is imported im app.module.ts but i still have this issue any help please if there is another module is missing ? UploadFileModule是从app.module.ts中导入的,但是如果缺少另一个模块,我仍然对这个问题有帮助吗?

You are importing your FileUploadModule in the app.module, which isn't where the Ajouter-produit.component.ts is declared. 您将在app.module中导入FileUploadModule,而不是在声明Ajouter-produit.component.ts的位置。 Import it in the module where the component is declared, in your case, AdminModule. 将其导入声明组件的模块中(在本例中为AdminModule)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获错误:模板解析错误:无法绑定到&#39;ngModel&#39;,因为它不是&#39;input&#39;的已知属性 - Uncaught Error: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input' Angular2测试 - 失败:未捕获(在承诺中):错误:模板解析错误:无法绑定到“消息”,因为它不是已知的属性 - Angular2 Testing - Failed: Uncaught (in promise): Error: Template parse errors: Can't bind to 'message' since it isn't a known property of 未捕获的错误:模板解析错误:无法绑定到“ FormGroup”,因为它不是“ form”的已知属性 - Uncaught Error: Template parse errors: Can't bind to 'FormGroup' since it isn't a known property of 'form' 未捕获的错误:模板解析错误:无法绑定到“配置文件”,因为它不是“ app-trnmnt-name”的已知属性 - Uncaught Error: Template parse errors: Can't bind to 'profiles' since it isn't a known property of 'app-trnmnt-name' 未捕获的错误:模板解析错误:由于它不是&#39;app-quote-create&#39;的已知属性,因此无法绑定到&#39;quotes&#39; - Uncaught Error: Template parse errors: Can't bind to 'quotes' since it isn't a known property of 'app-quote-create' Angular 4/5 未捕获错误:模板解析错误:无法绑定到“mat-dialog-close”,因为它不是“button”的已知属性 - Angular 4/5 Uncaught Error: Template parse errors: Can't bind to 'mat-dialog-close' since it isn't a known property of 'button' 错误:模板解析错误:无法绑定到“ ngForOf”,因为它不是“模板”的已知属性 - Error: Template parse errors: Can't bind to 'ngForOf' since it isn't a known property of 'template' 模板解析错误:无法绑定到“ngbTypeahead”,因为它不是“input”的已知属性 - Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of 'input' Angular 2:模板解析错误:无法绑定到&#39;ngModel&#39;,因为它不是&#39;input&#39;的已知属性 - Angular 2: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input' 模板解析错误:无法绑定到'ngbTypeahead',因为它不是'input的已知属性 - Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of 'input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM