I am encountering a problem with my component as the Angular Directive is missing

Recently, I incorporated a customized directive into my Angular app to allow file uploads via drag and drop. However, I encountered an issue where the command line kept throwing an error stating that my function does not exist within my component.

 Property 'fileBrowseHandler' does not exist on type 'UploadResumeComponent'.

I attempted to resolve this by adding it to my exports in my app.module.ts file, but unfortunately, that did not solve the problem. Any suggestions on how to fix this issue?

(Name of customized directive = DndDirective)

Thank you!

@NgModule({
declarations: [
  AppComponent,
  UploadResumeComponent,
  HeaderComponent,
  BannerComponent,
  SideMenuComponent,
  MainBodyComponent,
  FooterComponent,
  DndDirective,
  RhsWidgetComponent,
  ResumePreviewComponent,
  SkillsProfileComponent
],
exports : [
  DndDirective
],
imports: [
  BrowserModule,
  AppRoutingModule,
  HttpClientModule,
  [NgxDocViewerModule],
  PdfViewerModule
],
providers: [
{provide: COMPILER_OPTIONS, useValue: {}, multi: true},
{provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS]},
{provide: Compiler, useFactory: createCompiler, deps: [CompilerFactory]},
],
bootstrap: [AppComponent]
})

HTML FILE --

<div class="upload">
  <div class="drag-area" appDnd *ngIf="!main.uploadedResume">
  <input
    type="file"
    #fileDropRef
    id="fileDropRef"
    multiple
    (change)="fileBrowseHandler($event.target.files)"
    hidden
>

Custom Directive (TS file) --

   import { Directive, HostBinding, HostListener, Input } from '@angular/core';
// import { url } from 'inspector';
import { ApiService } from './services/api.service';
import { MainService } from './services/main.service';

@Directive({
  selector: '[appDnd]'
})

// @Input 

export class DndDirective {

@HostBinding('class.fileover') fileOver: boolean;

  // Dragover Listener
@HostListener('dragover',['$event']) onDragOver(evt) {
  evt.preventDefault();
  evt.stopPropagation(); 
  this.fileOver = true;

  console.log('Drag Over')
}

  // Dragleave Listener
@HostListener('dragleave',['$event']) public onDragLeave(evt) {
  evt.preventDefault();
  evt.stopPropagation(); 

  console.log('Drag Leave')
}

  // Drop Listener
@HostListener('drop', ['$event']) public ondrop(evt){
  evt.preventDefault();
  evt.stopPropagation();
  this.fileOver = false;
  const files = evt.dataTransfer.files;
  
  if(files.length > 0){

      //Do some stuff here
      // this.fileDropped.emit(files)
      this.getPreSignedUrl();
      this.main.uploadedResume = true;
      console.log("files", files)
      console.log(`You dropped ${files.length} files.`)
  }
}

Answer №1

CustomDirective - is this the directive you created?

Remember to include directives in the declarations section of your module. If it's already defined in another module, make sure to import that module into yours.

Note:

After reviewing your HTML code, it seems that the error is not related to your directive. The issue lies in your TypeScript file where a method named fileBrowseHandler is missing.

Ensure that this method is present in your UploadResumeComponent component.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Position components in Angular 2 based on an array's values

Hello all, I am a beginner in terms of Angular 2 and currently facing some obstacles. My goal is to create a board for a board game called Reversi, which has a similar layout to chess but with mono-color pieces. In order to store the necessary information, ...

Exploring ways to access elements within shadow-root (open) in Angular using SVG.js

I'm currently tackling a project involving Angular Elements. Within this specialized component, my goal is to incorporate SVG.js 3+. However, due to the necessity of utilizing ViewEncapsulation.ShadowDom in my component, I am encountering challenges w ...

Angular: Using ngrx for Nested HTTP Calls

Looking at my Angular code, I am trying to figure out how to convert nested HTTP calls into the ngrx pattern. My idea is to create separate actions for getUser and getPost, but I am struggling with passing the getUser response as a parameter to the getPo ...

Is there a way to properly install angular cli that is compatible with node version 13.14.0?

Running Windows 7, I attempted to install an outdated version of node - specifically node 13.14.0. However, when trying to install the Angular CLI with the command "npm i -g @angular/cli", an error occurred. Can anyone advise on what steps I should take ne ...

Angular: utilizing input type="date" to set a default value

Looking for a way to filter data by date range using two input fields of type "date"? I need these inputs to already display specific values when the page loads. The first input should have a value that is seven days prior to today's date, while the ...

What is the method for importing the merge function from "lodash/merge" in TypeScript?

When using ES6, it's possible to import only a single function from a library in order to reduce the overall bundle size. For example: import merge from "lodash/merge" But in TypeScript, the statement above can trigger a compile error: Cannot find m ...

Python Flask-Socketio server deployed on Google Cloud App Engine Flexible environment

I need assistance deploying a Flask SocketIO server on App Engine. Below are the necessary imports and how the server runs: from typing import List from flask_socketio import SocketIO, join_room, leave_room, send, emit from flask import Flask, render_ ...

Is it possible to compile a TypeScript file with webpack independently of a Vue application?

In my Vue 3 + Typescript app, using `npm run build` compiles the app into the `dist` folder for deployment. I have a web worker typescript file that I want to compile separately so it ends up in the root of the `dist` folder as `worker.js`. Here's wha ...

Fake AxiosInstance. In need of obtaining response in a single test

In my api.ts file import axios from 'axios' export const api = axios.create({ baseURL: 'http://localhost:3333/', }) Within my react-page.spec.tsx file: import React from 'react' import '@testing-library/jest-dom&apo ...

Different Option for Nginx Server

Currently I am utilizing an AWS EC2 instance to host both my NodeJs backend and Angular frontend. Additionally, I am leveraging Route 53 for routing purposes and purchased a domain from GoDaddy. The hosting process involved the following steps: For the b ...

The design of Next.js takes the spotlight away from the actual content on the

Recently, I've been working on implementing the Bottom Navigation feature from material-ui into my Next.js application. Unfortunately, I encountered an issue where the navigation bar was overshadowing the content at the bottom of the page. Despite my ...

The modules 'MdCardModule' and 'MdTooltipModule' do not have any exported members

Encountering Errors After Running ng build Issue found in C:/761/search- bar/workload_management_app/Client/src/app/app.module.ts (8,9): Module '"C:/761/search- bar/workload_management_app/Client/node_modules/@angular/materia ...

When trying to access a certain class property, I was met with the following error message: TypeError: Unable to read/set property 'x' of

Lately, I've delved into the realm of JavaScript / TypeScript and decided to create a basic React App using TypeScript. Within one of my components, I aim to switch between different components using a "state" (where each component will follow the pre ...

Encountered an issue in React and Typescript where the argument type is not compatible with the parameter type 'EventListenerOrEventListenerObject'

One challenge I am facing is integrating Typescript into my React project: componentDidMount() { document.addEventListener('mousemove', this.handleMouseMove); } private handleMouseMove = (e: React.MouseEvent<HTMLElement>) => { appS ...

What is the solution to the error message "Uncaught TypeError: createTheme_default is not a function"?

While working on my react application with vite, typescript, and mui, I encountered the following error: enter image description here This issue seems to be connected to material ui. Sometimes, deleting the 'deps' folder in '\node_mod ...

Creating dynamic content within Angular 2 components by utilizing innerHTML

As I work on documenting a component library, my goal is to have one string of HTML that not only displays the component on the page but also includes documentation for it. This is what I want: https://i.stack.imgur.com/bjp5u.png However, this is what I ...

Step-by-step guide for integrating Google Closure Library with Angular 10

Is there a way to integrate the Google Closure Library into an Angular 10 project? I attempted to install it using npm install google-closure-library, but encountered an error stating Could not find a declaration file for module 'google-closure-librar ...

Updating an Angular 2 project for the MEAN Stack development platform

A few weeks back, I embarked on an Angular2 project by following the "Tour of Heroes" tutorial. As I progressed, my project grew in complexity with routers, rest services, and hundreds of lines of code. Now, as I look to transition my project to the MEAN ...

Zero-length in Nightmare.js screenshot buffer: an eerie sight

I'm currently working on a nightmare.js script that aims to capture screenshots of multiple elements on a given web page. The initial element is successfully captured, but any subsequent elements below the visible viewport are being captured with a l ...

Transmitting a cookie across domains using an HTTP get request in Angular 2

Is there a way to send a cookie with Angular 2 across domains? const headers = new Headers({ 'Cookie': 'test=me'}); let options = new RequestOptions({ headers }); return this.http.get(this.specialUrl, options ) .map( (res: ...