簡體   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

    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

    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

    ...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 { }    

未被捕獲(承諾):錯誤:模板解析錯誤:無法綁定到“上載器”,因為它不是“輸入”的已知屬性。 (“

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 

UploadFileModule是從app.module.ts中導入的,但是如果缺少另一個模塊,我仍然對這個問題有幫助嗎?

您將在app.module中導入FileUploadModule,而不是在聲明Ajouter-produit.component.ts的位置。 將其導入聲明組件的模塊中(在本例中為AdminModule)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM