Accessing 'this' within the Angular 2 class is restricted

When trying to access this,

I encountered an issue when trying to set the value of this.idHidden to true.

For example: this.idHidden = true

The error message:

TypeError: Cannot set property 'idHidden' of null

And here is the code snippet:

import { Component , Output } from '@angular/core';
import { NgForm } from '@angular/forms';
import * as Datastore from 'nedb';

@Component({
  moduleId: module.id,
  providers: [],
  templateUrl: 'info.component.html'
})

export class InfoComponent {
  selkName: any;
  insertedSelk: any;
  idHidden: false;

  selkValidate: number;

  constructor(){
    this.selkName = '';
    this.insertedSelk = [];
    this.selkValidate = 1;
    this.SelkFinde(this);
  }
  
  DeleteSelk(id: number){
    let db = new Datastore({filename : 'ComerceDB'});
    db.loadDatabase(() => {
      db.remove({ _id: id }, {}, (err: any, numRemoved: any) => {
        this.idHidden = true;
        console.log(this.idHidden);
      });
    });
  }
}

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

Prevent saving the file until all the categories have been chosen

We have recently updated our file list by adding a new file category column. Our aim now is to prevent users from saving the form until a category has been assigned to each file. However, I am unsure how to check for the presence of a value in each file ...

The child components of the parent route in Angular 2 are organized as nested route components

Do nested route components act as children of the parent route component? Can they communicate by using an Output from a child route component to the parent route component? If not, what is the suggested approach in this scenario? Since components in rou ...

Issue with Type Inference in Callback Refs in Typescript React

Looking for a callback ref in my react component only. I've opted to utilize useState for this purpose. const [refElement, setReference] = useState(null); When rendering: <div // encountering a TypeScript error with this ref ref={setArrowElemen ...

Is it possible to make interface member optional in TypeScript?

Consider having a typescript interface defined like this: interface IOptions{ name: string; dob: date; gender: string; } Now, what if you need to create another interface that extends the above interface? Here is an exampl ...

What is the best way to display data retrieved through an HTTP service using ngFor?

I was attempting to inject a service (contact.service.ts) into a component (contact-list.component). The service contains data on employees defined in contacts.ts. While I was able to successfully receive the data, I encountered difficulty in rendering it ...

NextJS and Context API throwing a Typescript error

I've been working on my _app.tsx file and here's the code snippet I have: import React from 'react' import type { AppProps } from 'next/app' /* Import Styles */ import '@themes/index.scss' /* Import Template */ imp ...

Type errors in NextJS are not being displayed when running `npm run dev`

When encountering a typescript error, I notice that it is visible in my editor, but not in the browser or the terminal running npm run dev. However, the error does show up when I run npm run build. Is there a method to display type errors during npm run d ...

Changing the name of a tab within a p-tabview

Setting up a p-tabview with tabs containing specific content involves the following code: <p-tabView class="tabmain" > <ng-container *ngFor="let tab of tabs"> <p-tabPanel [header]="tab.header" > ...

Tips for dividing by a large number

I am currently attempting the following: const numerator = 268435456; const denominator = 2 ** 64; const decimalFraction = numerator / denominator; In order to achieve this, I have experimented with utilizing the code provided in this link: : const rawVal ...

What is the process for incorporating a custom action in TestCafe with TypeScript?

I've encountered an issue while trying to implement a custom action. When running tests with the new custom action, I keep receiving an error stating that my custom action is not recognized as a function. TypeError: testcafe_1.t.customActions.selectFr ...

What is the best way to transfer variables from an ng-template defined in the parent component to a child component or directive?

Is there a way to pass an ng-template and generate all its content to include variables used in interpolation? As I am still new to Angular, besides removing the HTML element, do I need to worry about removing anything else? At the end of this ...

Having Trouble Importing a Dependency in TypeScript

My experience with using node js and typescript is limited. I attempted to include the Paytm dependency by executing the following code: npm install paytmchecksum or by inserting the following code in package.json "dependencies": { ... & ...

When implementing TypeScript in Next.js, the web worker is not loading correctly

For my project, I am utilizing Next.js which utilizes Webpack 5 for bundling. I came across this webworkers guide that suggested using the following syntax to load web workers: new Worker(new URL('./worker.js', import.meta.url)); However, when I ...

Oops! Looks like there's a problem with the syntax - the import statement can't be

I encountered an error while trying to create Sequelize migrations in my Node.js app (which is set up with Typescript). When running npx sequelize-cli db:migrate, I received an "import method" error, but I'm unable to pinpoint the source of this issue ...

display a list of items in the dashboard using Angular 2 md-sidenav when clicked

I've successfully implemented a sidebar navigation menu in Angular 2, resembling the image shown in the link below: https://i.sstatic.net/KFvJQ.jpg UPDATE: However, I'm facing an issue where clicking on a category link within the sidebar doesn ...

Tips for Managing the Hardware Back Button in Ionic 3

Can someone help me enable the hardware back button in Ionic 3? I want it to redirect to specific pages and display designated content. Being new to Ionic 3, I need guidance on how to set up the hardware device buttons for redirection. ...

Utilizing Angular to import an SVG file from a backend and incorporate its content as a template

I am looking for a solution to load an SVG date from my Spring Boot backend and utilize it as an Angular template. Currently, the request is structured like this: getSVG (): Observable <any> { return this.http.get(`${environment.apiUrl}/path ...

How come I am unable to fetch classes and enums from a namespace?

When using Typescript with pg-promise, I am facing an issue where I can't import the classes and enums as I normally would. Typically, when working with a library, I import a type, use it, and everything functions properly. However, in the snippet bel ...

Configuring dependencies in Ionic2 and Angular2 for seamless integration

I need to configure a global configuration file or from app.ts. We want to pass configuration settings that can be automatically used in our dependency injection system. Service for Api.ts import {Injectable} from 'angular2/core'; import {Http ...

Switching Theme Dynamically in a Multi-tenant Next.js + Tailwind App

I'm currently developing a Next.js + Tailwind application that supports multiple tenants and allows each tenant to easily switch styles or themes. I've been struggling with the idea of how to implement this feature without requiring a rebuild of ...