Tag: "AngularObjectUnsubscribedError"

Encountering a bug in my code

ObjectUnsubscribedErrorImpl {message: 'object unsubscribed', name: 'ObjectUnsubscribedError', ngDebugContext: DebugContext_, ngErrorLogger: ƒ} message : "object unsubscribed" name : "ObjectUnsubscribedError"

This is the piece of code causing the issue:

 clickSubject: Subject<any> = new Subject();

  l_getClickButtonCancella(event: boolean) {
    if (event) {
      this.clickSubject.next(1);
    }
  }

Seeking suggestions on how to resolve this problem. Any ideas?

Answer №1

Make sure to double-check your code for any instances of unsubscribing the subject (Simply remove the unsubscribe function from the subject to resolve the issue!), as that seems to be causing the error. Feel free to refer to the stackblitz below where I recreated your situation!

import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { Subject } from 'rxjs';
import 'zone.js';

@Component({
  selector: 'app-root',
  standalone: true,
  template: `
    <h1>Hello from {{ name }}!</h1>
    <a target="_blank" href="https://angular.dev/overview">
      Learn more about Angular
    </a>
  `,
})
export class App {
  clickSubject: Subject<any> = new Subject();
  name = 'Angular';

  ngOnInit() {
    this.clickSubject.next(1);
    this.clickSubject.unsubscribe(); // Remove this line
    this.clickSubject.next(1);
  }
}

bootstrapApplication(App);

Check out the stackblitz here

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

How can I expand and collapse elements using Angular?

I'm looking to implement a collapsible feature. When the user clicks on the "Section Title", I want the corresponding information to collapse or expand. @Component({ selector: 'knowledge-base', template: ` <div *ngFor="let sect ...

Ensuring Type Compatibility Between Classes and Object Literals in TypeScript

When working with TypeScript, it is important to note that an object literal can be assigned to a class typed variable as long as the object provides all properties and methods required by the class. class MyClass { a: number; b: string; } // The co ...

A step-by-step guide to customizing the Material UI Chips delete SVG icon to appear in white color through

Using a Material UI component, I added a custom class to my chip. Attached is a screenshot showing what I mean. Currently, I am attempting to change the color of the cross button to white. After inspecting the element, I discovered that it is an SVG ico ...

Received an error while using Mongoose 6 $group with Typescript stating that the property '_id' is not compatible with the index signature

Recently, I've been transitioning from JavaScript to TypeScript and also upgrading from mongoose 5.8 to version 6.1. The code snippet below used to work perfectly before: let getActionsTakenByApp = (store_url: string) => { return AppAction.aggr ...

Create a streaming service that allows for multicasting without prematurely ending the main subject

In my implementation of caching, I am utilizing BehaviorSubject and multicast. The cache stream should begin with an HTTP request and I want the ability to manually trigger a cache refresh by calling next on the subject. While the conventional method of us ...

Organize the attributes of components on the following line in Visual Studio Code

Is there a method to configure the VS code formatter for Angular 2+ templates to ensure that attributes are wrapped in a new line? I prefer this formatting: <app [input1]="input1$ | async" [input2]="input2$ | async" (inputChanged)="set ...

Encountering a MongooseServerSelectionError: connection failure to 127.0.0.1:27017 while trying to connect to MongoDB

I am currently working on a basic node.js TypeScript API with MongoDB integration, and I am utilizing Docker to containerize the application. Below is a snippet from my index.ts file: import express from 'express'; import app from './app&ap ...

Unable to locate the specified control using path 'myFormArray -> [index] -> myProperty'

I'm currently facing an issue while attempting to create a dynamic form using Angular ReactiveForms. The error message Cannot find control with path 'myFormArray -> [index] -> myProperty keeps popping up, despite following solutions found o ...

Ensuring Type Safety for Collections in TypeScript

My code snippet looks like this: portfolioList: MatTableDataSource<Portfolio>; ngOnInit(): void { this.backend.getStatement().subscribe( list => { if(list as Portfolio[]) this.portfolioList = new MatTableDataSource(l ...

How to retrieve a document with Angular 6 and Spring REST services

I am facing an issue while trying to download a file from a REST API using Angular 6 Back-end Method @RequestMapping(value = "/print/{id}") public ResponseEntity<byte[]> generateReport(@PathVariable("id") long id_project){ Map<Stri ...

determine the discrepancy between two time periods

I am facing an issue while trying to calculate the time difference between two hours in my code snippet: changEndHour($event: any, i: number) { var arrayControl = this.generalForm.get('hours') as FormArray; let startHour = arrayControl. ...

The third-party SDK no longer includes names and autocomplete functionality

I am encountering an issue where my previously working SDK environment has suddenly stopped recognizing names and providing autocomplete. I am wondering what could have caused this problem - is it related to SDK maintenance or is the SDK offline? The SDK ...

What is the best way to transform the date time format received from the server so that it can be used with the time-ago

Issue Explanation: My server is providing the date and time in a specific format as shown below - myDate2= '22-DEC-2017 03:22:11'; The current format does not work with time-ago-pipe and results in NaN Accepted Format: myDate: String = new Dat ...

What is the best way to enable `child_process.execFile` to utilize an existing running application?

I am currently developing an Electron app that is designed to launch another application, such as Photoshop, using child_process.execFile. However, I have encountered an issue where if Photoshop is already running when child_process.execFile is called, a n ...

Encountering difficulties when compiling my Angular application

Currently, I am working with Angular 2. To include Bootstrap in my project, I utilized the node.js command prompt for installation. npm install ngx-bootstrap --save I made adjustments to the .csproj file in order to deploy my application on the server vi ...

What strategies can I implement to streamline the use of these functions instead of creating a separate one for each textfield

Currently, I am learning how to use spfx with SPO (SharePoint Online). In my form, there are multiple text fields that need to be handled. I have two class components named A and B. Whenever a textfield in component B is typed into, a function sends the in ...

Is it more beneficial to convert all the current jQuery AJAX webparts into Typescript or should I opt to inject the existing jQuery into SPFX instead?

Transitioning from SharePoint 2013 to SharePoint online raises the question of how to migrate existing webparts that utilize jquery - ajax to SPFX client webparts. One possibility is rewriting all the code in Typescript, but is it possible to simply inje ...

Why does TypeScript include a question mark next to the argument when GraphQL specifies it as nullable true?

// image.entity.ts import { Field, ObjectType } from '@nestjs/graphql'; import { Column, DeleteDateColumn, Entity, PrimaryGeneratedColumn, } from 'typeorm'; @ObjectType() @Entity() export class ImageEntity { @PrimaryGenerate ...

Can you explain the significance of this code snippet 'true <=> false'?

Today I came across this piece of code: true <=> false. I'm a bit confused by it and don't really understand how it works. If anyone could shed some light on this expression for me, I would greatly appreciate it. For reference, this code ...

Error: Unable to access the 'push' property of an undefined variable in Ionic 3

I encountered an issue while attempting to redirect to a different page after a successful callback. The error message that I received was TypeError: Cannot read property 'push' of undefined this.http.post('http://localhost:3030/users&apos ...