Git Product home page Git Product logo

Comments (5)

JoelNieto avatar JoelNieto commented on June 2, 2024 1

Hi, thanks for your response, I already solved it. FWIW, this is the complete implementation:

Custom Dropzone:

import { ChangeDetectionStrategy, Component } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { DropzoneCdkModule, DropzoneComponent } from '@ngx-dropzone/cdk';

@Component({
  selector: 'sk-file-zone',
  standalone: true,
  imports: [DropzoneCdkModule],
  providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: FilezoneComponent }],
  template: ` <div class="my-dropzone" (click)="onContainerClick()">
    <ng-content select="[fileInput]"></ng-content>
    <ng-content select="[items]"></ng-content>
  </div>`,
  styles: `.my-dropzone {
        cursor: pointer;
        text-align: center;
        padding: 40px;
        background: platinum;
        border: 1px solid black;
  }

  .dragover > .my-dropzone {
    border-width: 2px;
  }`,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FilezoneComponent extends DropzoneComponent {
  public onContainerClick(): void {
    this.openFilePicker();
  }
}

Using the custom dropzone

import { Component } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { DropzoneCdkModule, FileInputValue } from '@ngx-dropzone/cdk';

import { FilezoneComponent } from '../../../../components/filezone/filezone.component';

@Component({
  standalone: true,
  imports: [FilezoneComponent, DropzoneCdkModule, ReactiveFormsModule],
  template: `<div class="mt-3">
    <sk-file-zone>
      <input
        type="file"
        fileInput
        [formControl]="fileControl"
        mode="append"
        multiple
      />
      <div items>
        @for (file of files; track file.name) {
          <div>{{ file.name }}</div>
        }
      </div>
    </sk-file-zone>
  </div> `,
})
export class AssignmentWorkComponent {
  public fileControl = new FormControl<FileInputValue>(null);

  get files(): File[] {
    const files = this.fileControl.value;

    if (!files) return [];

    return Array.isArray(files) ? files : [files];
  }
}

The DropzoneCdkModule must be imported on both components.

from ngx-dropzone.

hackingharold avatar hackingharold commented on June 2, 2024

Hi @mcfdez,

I guess you forgot to import the DropzoneCdkModule into the same module which defines your ImageDropzone.
Please test this out.

// in app.module.ts
import { DropzoneCdkModule } from '@ngx-dropzone/cdk';

@NgModule({
  ...
  imports: [
    DropzoneCdkModule,
  ],
  declarations: [
    ImageDropzoneComponent
  ],
  ...
})
export class AppModule { }

from ngx-dropzone.

JoelNieto avatar JoelNieto commented on June 2, 2024

Hello,
I'm having the same issue using Angular 17 and standalone components, already imported the DropzoneCdkModule in the app main.ts and the wrapper component, and it's showing the same error. Any help with this?

from ngx-dropzone.

hackingharold avatar hackingharold commented on June 2, 2024

Hi there, the dropzone component itself is not a standalone component.
Can you please provide an example so I can test this?

from ngx-dropzone.

hackingharold avatar hackingharold commented on June 2, 2024

Great! 👍🏼

from ngx-dropzone.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.