Unexpected Reference Error arises in the application, although it functions properly in Stackblitz

This innovative directive concept functions smoothly in Firefox's StackBlitz environment, but encounters an Uncaught Reference Error when integrated into my application. The displayed error in the browser is shown below:

https://i.sstatic.net/HLtxq.png

Context: The directive is implemented on the parent element and interacts with its child nodes. It is designed to calculate and scroll to the child component whose x-midline is closest to the parent's midline upon a (mouseup) event within the host parent view box container. Any helpful insights would be greatly appreciated! Thank you.

Directive Implementation:

import { Directive, OnInit, AfterViewInit, Input, HostListener, ElementRef } from '@angular/core';

@Directive({
  selector: '[windowsnap]'
})
export class WindowSnapDirective implements OnInit, AfterViewInit {

  scrollhistory = [];
  parent = this.el.nativeElement;

  constructor(private el: ElementRef) {
    console.log('Constructor of windowsnap directive');
  }

  ngOnInit() {
    console.log('Initialization of windowsnap directive');
  }

  ngAfterViewInit() {
    console.log('AfterViewInit of windowsnap directive');
  }

  closest(num, arr) {
    let curr = arr[0];
    arr.forEach((val) => {
      if (Math.abs(num - val) < Math.abs(num - curr)) {
         curr = val
      }
    });
    return curr;
  }

 @HostListener('mouseup') onMouseUp() {
    this.scrollhistory.unshift(this.parent.scrollLeft);
    console.log(this.scrollhistory)

    if(this.parent.scrollLeft != this.scrollhistory[1]){

    let child1El = this.parent.querySelector('child1');
    let child2El = this.parent.querySelector('child2');
    let child3El = this.parent.querySelector('child3');

    let child1leftBoundary:number = child1El.offsetLeft;
    let child1middleBoundary: number = child1El.offsetWidth * 0.5 + child1leftBoundary ;
    let child1rightBoundary: number = child1El.offsetWidth + child1leftBoundary ;

    let child2leftBoundary:number = child2El.offsetLeft;
    let child2middleBoundary: number = child2El.offsetWidth * 0.5 + child2leftBoundary ;
    let child2rightBoundary: number = child2El.offsetWidth + child2leftBoundary ;

    let child3leftBoundary:number = child3El.offsetLeft;
    let child3middleBoundary: number = child3El.offsetWidth * 0.5 + child3leftBoundary ;
    let child3rightBoundary: number = child3El.offsetWidth + child3leftBoundary ;

    let viewBoxL = (this.parent.scrollLeft)
    let viewBoxC = (this.parent.scrollLeft + (this.parent.offsetWidth * 0.5))
    let viewBoxR = (this.parent.scrollLeft + (this.parent.offsetWidth))

    let a = (viewBoxC-child1middleBoundary)
    let b = (viewBoxC-child2middleBoundary)
    let c = (viewBoxC-child3middleBoundary)

    let closestChildMid = this.closest(0, [a, b, c])
    console.log("closest: " + closestChildMid)

    if(closestChildMid === a){
    child1El.scrollIntoView({behavior: "smooth", block: "center"});
    }

    if(closestChildMid === b){
    child2El.scrollIntoView({behavior: "smooth", block: "center"});
    }

    if(closestChildMid === c){
    child3El.scrollIntoView({behavior: "smooth", block: "center"});
    }
  }
}
}

Answer №1

There is an additional comma

declare class ScreenMoveDirective implements OnDestroy, AfterContentInit, {

The correct way is

declare class ScreenMoveDirective implements OnDestroy, AfterContentInit {

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

Having trouble installing the Angular/CLI on macOS Mojave due to a node-pre-gyp error?

I recently formatted my iMac and deleted all files on the hard drive. However, upon installing Angular CLI 7, I encountered an error log message in the terminal console. Environment macOS: Mojave 10.14.2 node: v10.15 npm: 6.4.1 Console Error miguels- ...

What is the reason for not applying type guards to callback function arguments?

Check out this TypeScript code snippet for a quick example. // Setting up the example declare var data:{info?: {details: string}}; function instant(callback: () => void) { callback(); } // Safeguarding the data if (data.info) { console.log(data.inf ...

What's the alternative now that Observable `of` is no longer supported?

I have a situation where I possess an access token, and if it is present, then I will return it as an observable of type string: if (this.accessToken){ return of(this.accessToken); } However, I recently realized that the of method has been deprecated w ...

Is it possible to enter NaN in Vue3?

Is there a way to handle NaN values and keep a field blank instead when calculating margins with a formula? https://i.stack.imgur.com/JvIRQ.png Template <form> <div class="row"> <div class="mb-3 col-sm ...

Automate the compilation of Typescript project references by creating a solution that allows for passing unique options to each

When compiling or building a project with references programmatically, I make use of the ts.createSolutionBuilder API. The challenge I face is that in my specific scenario, I do not have individual tsconfig.json files stored on the filesystem for each pac ...

"Utilizing Typescript's keyof operator on its own

I'm grappling with the challenge of creating a type that can utilize the typeof its own keys, but I'm hitting a roadblock. Below is a simplified version of what I'm attempting to achieve: type SpecialType = Record<string, (getter: <K e ...

Identifying and organizing scroll-related errors in AngularJS using TypeScript clustering

Attempting to incorporate lazy loading using Clusterize.js in AngularJS TypeScript, but encountering errors. Any expert advice would be greatly appreciated. HTML VIEW <div id="scrollArea" class="clusterize-scroll"> <ul id="contentArea" clas ...

Ways to bounce back from mistakes in Angular

As I prepare my Angular 5 application for production, one issue that has caught my attention is how poorly Angular handles zoned errors. Despite enabling 'production mode', it appears that Angular struggles to properly recover from these errors. ...

Trigger the React useEffect only when the inputed string matches the previous one

Currently, I am in the process of creating my own custom useFetch hook. export const useFetch = <T extends unknown>( url: string, options?: RequestInit ) => { const [loading, setLoading] = useState(false); const [error, setError] = ...

Incorporate PrimeNG into an Angular2 application with the help of Webpack

I've been trying to integrate PrimeNG into my Angular2 application bundled with Webpack. To start, I executed the following npm commands: npm install primeng --save npm install primeui --save This updated my package.json with the following entries: ...

What could be causing the tap operator to fail to fire in this scenario?

I'm struggling to understand why the rxjs tap() operator is not firing in my Angular component, even though the Subject value is being updated on the screen. I've also experimented with using a BehaviorSubject instead, but encountered the same is ...

Locate the closest point among a set of coordinates to a specified point

I have a situation where I have an object that contains latitude and longitude attributes. My goal is to find the closest match in an array of similar objects by considering both latitude and longitude. obj = {latitude: 55.87, longitude: 4.20} [ { & ...

Retrieving the computed value created from an axios get request in Vue

I am attempting to retrieve the computed value in created for a GET request. I have declared the classroomBackground as a string in my data. data() { return { classroomBackground: '' as string, ...

I need to explicitly tell TypeScript that there are optional numeric properties on two objects that need to be compared

I am faced with the challenge of sorting an array of objects based on an optional integer property called order, which falls within the range of [0, n]. To achieve this task, I am utilizing JavaScript's Array.prototype.sort() method. Given that the p ...

Show various perspectives depending on the circumstances

I am looking for a solution to display a different component if my ngFor loop returns null. <ion-select interface="popover" [ngModel]="selectedKidId"> <ion-option *ngFor="let kid of kids" [value]="kid.id">{{kid.name}}</ion-option& ...

The timezone plugin in day.js may sometimes generate an incorrect date

For a while, I've been using dayjs in my angular project to convert timestamps from UTC to localtime. However, after my recent update, this functionality stopped working. This isn't the first issue I've encountered with dayjs, so I decided t ...

Incorporating Modernizr into your Angular 2 project with Typescript definitions

I'm currently working on incorporating Modernizr support into my Angular2 project. After setting up the tsconfig, webpack.config, and package.json files, I was able to successfully build the project. However, I am encountering difficulty in importing ...

Error: No 'map' property found in 'TwitterserviceService' type

Currently, I am in the process of learning how to develop simple and basic Angular applications. As part of my learning journey, I decided to incorporate my Twitter timeline into one of my projects. To aid me in this endeavor, I referred to various online ...

typescript exploring the versatility of dynamic types and generics

Understanding TypeScript dynamic and generic types can be challenging for me. The goal is to create a function that generates an object with a specific type, where some properties of the object must match the parameters provided to the function. Essentia ...

Utilizing NPM Workspace Project in conjunction with Vite to eliminate the necessity of the dist folder during the Vite build process

I am currently working on a project that involves a module using full path exports instead of index files. This project is divided into 2 NPM workspaces: one called core and the other called examples. The challenge I am facing is avoiding long import pat ...