Switching between dynamic Angular template classes

Creating an Angular HTML template with reactive form:

<div class= "one">
<button class = "verticalButtonClass" (click) = "onClick()"> Label4 </button>
</div>

<div class = "two">
</button>
<button class = "horizontalButtonClass" (click) = "onClick()"> Label14 </button>
<button class = "verticalButtonClass"   (click) = "onClick()"> Label15 </button>
</div>

<button class = "three"
    [class.verticalButtonClass] = "m_bool_variable"
    [class.horizontalButtonClass] = "!m_bool_variable"
    (click) = "m_bool_variable.setValue( false )"> XCV </button>

CSS:

.verticalButtonClass
{
    color: blue;
    background-color: red;
    
    display:block;
    width: 100px;
    border: 2px solid green;
    margin-bottom: 2px;
}

.horizontalButtonClass
{
    color: blue;
    background-color: lightgreen;
    
    float:left;
    width: 100px;
    border: 2px solid green;
    margin-left: 2px;
}

.ts file:

import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';

@Component({
  selector: 'app-vertical',
  templateUrl: './vertical.component.html',
  styleUrls: ['./vertical.component.css']
})
export class VerticalComponent implements OnInit 
{
    m_bool_variable = new FormControl( false );

  constructor() { }

  ngOnInit(): void 
  {
    this.m_bool_variable.setValue( true );
  }

  onClick()
  {
    console.log("asdasd")
  }

}

Initially, the button shows a red color due to the variable being set to true. However, upon clicking the button, the color does not change to green.

Please provide feedback on the issue.

Answer №1

The variable m_bool_variable will consistently evaluate to true, regardless of the input value of the form control, due to its nature as an object. To retrieve the control's value, access m_bool_variable.value

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

Experience a unique double scrolling effect using the react-spring parallax and react-three-fiber Canvas components

My goal is to create a scrolling box with a parallax effect, but I'm facing an issue where it won't bind with the Canvas element, even when both are included under the same div. In the screenshot provided, you can see div1 and div2 each having t ...

Terminate child process with specified user ID using the Forever-monitor

Whenever I need to create new child node processes, I use the following code: var forever = require('forever-monitor'); function startNodeProcess(envVariables, jsFileName, uid) { var child = new (forever.Monitor)(jsFileName, { ...

Typescript enhances React Native's Pressable component with a pressed property

I'm currently diving into the world of typescript with React, and I've encountered an issue where I can't utilize the pressed prop from Pressable in a React Native app while using typescript. To work around this, I am leveraging styled comp ...

Associate a unique identifier string with a randomly generated integer identifier by Agora

For my current web project, I am utilizing a String username as the UID to connect to the channel in an Agora video call. However, I now need to incorporate individual cloud recording by Agora into the project. The challenge lies in the fact that cloud r ...

Incorporating a JavaScript advertisement zone within a PHP function

Currently in the PHP template, I am trying to embed a JavaScript ad zone inside a function in order to have control over each page's ad placement. Here is what I have: <?php if(is_page('welcome-president')) { oiopub_b ...

Should each navigation item be enclosed within its own div element?

Currently, I am studying HTML + CSS and developing a website that requires a vertical navigation bar on the left side with four interactive elements. I'm wondering if it is customary to enclose each of these four elements in a div, or if there is a mo ...

The curious case of Jade view caching in Express

Recently, I updated my Node.js and Express to versions 0.10.21 and 3.4.4, respectively, and now I'm encountering some strange view caching issues during development (as well as production). It appears that the HTML generated from views included withi ...

Adding dynamic metadata to a specific page in a next.js app using the router

I was unable to find the necessary information in the documentation, so I decided to seek help here. My goal is to include metadata for my blog posts, but I am struggling to figure out how to do that. Below is a shortened version of my articles/[slug]/page ...

Aligning content in CSS for cross-browser compatibility with Internet Explorer and Chrome

My CSS grid has grid items that can easily be centered in Chrome by using the justify-items:center property, creating a magical effect. However, this solution does not work in Internet Explorer as the items remain stuck to the left side. For reference: ht ...

Struggling to retrieve CSS property from a child element?

Check out this HTML snippet: <div id="ctr" class="faden-slider-container"> <div class="conteneur-image" ></div> <div class="conteneur-image" ></div> <div class="conteneur-image" ></div> </div> ...

The CustomValidator ClientValidationFunction will only activate on the second or subsequent submission if CheckBoxList is checked

I am encountering an issue with a user control that is dynamically added to pages on DNN. The user control is built on a customized version of CheckBoxList and includes a CustomValidator with ClientValidationFunction set to a javascript function. It works ...

Iterate through each image within a specific div element and showcase the images with a blur effect applied

I have a div with multiple images like this: <div class="am-container" id="am-container"> <a href="#"><img src="images/1.jpg"></img></a> <a href="#"><img src="images/2.jpg"></img>< ...

Adjust the background image color with CSS styling

I have a collection of icons that I would like to incorporate into my application. These icons primarily consist of glyphicons with a few others mixed in. I want the HTML structure to mimic that of a glyphicon, specifically: <a href="#"> <spa ...

Creating a full-width Bootstrap layout with dual backgrounds and a two-column structure

Explaining this concept is quite difficult, which is why I haven't been able to find an answer on Google. I am currently using Bootstrap 3 and I am trying to create a layout with a full width background image, along with two transparent color backgro ...

Harnessing the power of the Zurb Foundation 4 grid system to create visually appealing list elements

When it comes to styling the layout of a page, Foundation 4's grid system with its mobile-first approach is a no-brainer, especially if you're already using other foundation elements like textual content, images, and sidebars. On the example pag ...

Error: The react.js application is unable to access the property 'classList' of a null object

I've encountered a bug that's been causing me some trouble. Every time I try to run my react application, I keep getting an error message that reads TypeError: Cannot read property 'classList' of null. As someone who is new to react, I& ...

filtering the properties of mongoose documents

I have created a schema as shown below: var UserSchema = new Schema({ firstName: { type: String, required: true }, lastName: { type: String, required: true }, email: { type: String, required: true }, location: { type: String, required: true }, p ...

Having trouble accessing $scope outside of the constructor in Typescript/AngularJS?

Why is it that I can't access $scope outside of the constructor, unless I use the fat arrow function? Is there a way to access $scope without using the fat arrow function? namespace FooBar { export interface MyScope extends ng.IScope { me ...

After subscribing, creating the form results in receiving an error message that says "formgroup instance expected."

I am currently working on a project using Angular 6 to create a web page that includes a form with a dropdown menu for selecting projects. The dropdown menu is populated by data fetched from a REST API call. Surprisingly, everything works perfectly when I ...

Phonegap application functioning smoothly on computer, encountering issues on mobile device

Hey there! I recently developed a phonegap app that retrieves JSON data from a YQL link and presents it to the user. It works perfectly on Google Chrome desktop, but my client mentioned that it doesn't work on his Android 2.3 device. Could you help me ...