Determine if an element in Angular 6 contains a particular style

Below is a div, and the first time you click on it, an opacity style is added. I am looking to determine within the same function if this div has an opacity style set to 1.

@ViewChild('address')
private address: ElementRef;

public onClickAddress() {
  this.renderer2.setStyle(this.address.nativeElement, 'opacity', '1');
  // check if this element has an opacity style = 1
}

<div #address (click)="onClickAddress()">

</div>

Answer №1

Check out the demo - no need to use the renderer2.

When the address is clicked, its opacity is set to 1. If the opacity is already 1, the message "hello" is logged to the console. The code then checks if the element's opacity style is equal to 1.

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

The matInput directive is experiencing issues when used in a module that is loaded laz

After implementing a lazy loading module, I encountered an issue where elements like matInput were not displaying correctly. Even though the MatInputModule was imported in the module as expected: const routes = [ {path: '', component: AddPlace ...

problem encountered when running "ionic cordova build android --prod --release"

A chat application has been developed using Ionic2. Upon attempting to generate a production build with ionic cordova build android --prod --release, the following error is encountered. Error: ./node_modules/rxjs/observable/BoundCallbackObservable.js ...

setting up angular 4 application on an IIS server

When running ng build --prod --base-href=/my folder/subfolder/, I also made sure to copy the dist folder into the specified subfolder. After setting the physical path in IIS, I tried to browse the site but only encountered a blank screen with no error mes ...

Detect errors in the `valueChanges` subscription of Firestore and attempt a retry if an error occurs

My Angular app utilizes Firestore for storing data. I have a service set up to retrieve data in the following way: fetchCollectionColors(name) { this.db.collectionGroup('collection-colors', ref => ref.where('product', '==&ap ...

The compatibility between Typescript methods and event handlers is lacking

Consider this basic TypeScript script class foo { v: number = 1; public bar() { console.log(this.v); } } var a = new foo(); var b = new foo(); document.getElementById('test').addEventListener("click", a.bar); document.getE ...

Issue with separatorKeys functionality in ng2-tag-input

I've been experimenting with the ng2-tag-input module using a simple configuration: import { Component } from '@angular/core'; @Component({ moduleId: module.id, selector: 'search-form', template: `<tag-input [( ...

What is the best way to utilize typed variables as types with identical names in Typescript?

Utilizing THREE.js with Typescript allows you to use identical names for types and code. For instance: import * as THREE from '/build/three.module.js' // The following line employs THREE.Scene as type and code const scene: THREE.Scene = new THRE ...

What is the process for listening to custom events in Angular 4 components that have been loaded using routing?

In the app.component.html file <li routerLinkActive="active current"> <a [routerLink]="['/stats']"> Cluster stats </a> </li> When we route to the DisplayAllStatsComponent, how can we ...

Files are nowhere to be found when setting up an angular project

After creating an Angular project, I noticed that some key files were missing in the initial setup, such as app.modules.ts and app-routing.modules.ts The project was generated using the command ng new name Here is a screenshot displaying all the files th ...

The Nrwl Nx administrative page located within the server instance

Hopefully my question is clear. We are working with a monorepo at nrwl that includes 2 applications, client and client-admin. I'm looking for the best way to deploy both of these applications on the same server but with different routes. Client-app ...

What is the best way to check for duplicate email input when using knex?

Currently, I am in the process of developing an application using node.js, knex.js, typescript, zod, and fastify. My main focus is on validating emails during user registration. If a duplicate email is inserted, I want the system to throw a 401 (conflict) ...

Angular2: Property binding authorization is not implemented in any directive within an embedded template

I created a directive in Angular 2, but it is not working and returning a template parse error. Directive code : import { Directive, Input } from '@angular/core'; import { TemplateRef, ViewContainerRef } from '@angular/core'; import { ...

Having trouble uploading a PNG image (logo) with Cypress

I have been attempting to upload a png file using Cypress and here is what I have tried so far: Cypress.Commands.add('upload_image', (fileName, selector) => { return cy.get(selector).then(subject => { return cy.fixture(fileName, &apo ...

Extending Error object disrupts `instanceof` validation in TypeScript

Could someone clarify why the error instanceof CustomError part of the code below returns false? class CustomError extends Error {} const error = new CustomError(); console.log(error instanceof Error); // true console.log(error instanceof CustomError); ...

What is the best way to confirm the return type of a React.Component instance?

When working with TypeScript, there is a React Component called Cell: class Cell extends Component<void, void> { ... } Using it like this: <Cell /> The return type being received is JSX.Element. However, I want to make sure that the return ...

Encountering issues while attempting to transmit several files to backend in React/NestJS resulting in a BAD REQUEST error

My goal is to allow users to upload both their CV and image at the same time as a feature. However, every time I attempt to send both files simultaneously to the backend, I encounter a Bad Request error 400. I have made various attempts to troubleshoot th ...

"Exploring data trends with an ng2-charts line graph displaying x and y axis values

I am attempting to showcase a function using ng2-charts, with a specific set of x and y values. However, the display is currently not showing my values correctly. https://i.sstatic.net/1iULy.png Here is an example dataset: chartDataSet: ChartDataSets[] = ...

Angular outputting a basic static value

After searching extensively for a solution to my issue with Angular output, I have only come across ways to emit events. In my specific scenario, I have a parent component containing a router, and I need to dynamically change the title based on a value f ...

Issue with Npm installation command on Windows 7 64-bit system

When I run the command "npm install" from my project folder, I encounter the following errors: Error: Windows_NT 6.1.7601 Node version: v6.10.3 NPM version: v3.10.10 Code: ENOTFOUND Network error: getaddrinfo ENOTFOUND registry.npmjs.org regist ...

Error message: NextJs throws aReferenceError when trying to access the document object on page refresh

encountered the error ReferenceError: document is not defined when attempting to refresh the page I am working on creating a component using react-quill and then calling that component within a page. This is my component : import React, { useState } from ...