Having trouble getting the styles property to work in the component metadata in Angular 2?

Exploring Angular 2 and working on a demo app where I'm trying to apply the styles property within the component metadata to customize all labels in contact.component.html.

I attempted to implement

styles: ['label { font-weight: bold;color:red }']
but unfortunately, the CSS effects are not reflecting on my views.

Although aware of using

styleUrls: [ '../css/contact.component.css' ]
, I prefer understanding how to manipulate the styles property directly within the component metadata.

If anyone has suggestions as to why the effects are not being displayed on the views, please let me know!

@Component({
      moduleId: module.id,
      selector: 'app-contact',
      templateUrl: '../views/contact.component.html',
      styles: ['label { font-weight: bold;color:red }']
    })
    

Contact.component.html:

<h2 highlight>Contact of {{userName}}</h2>
    <h2 myHighlight>This is custom my directive</h2>
    <div *ngIf="msg" class="msg">{{msg}}</div>
    <form *ngIf="contacts" (ngSubmit)="onSubmit()" #contactForm="ngForm">
        <h3 >{{ contact.name | awesome }}</h3>
    
        <div class="form-group">
            <label for="name">Name</label>
            <input type="text" class="form-control" required [(ngModel)]="contact.name" name="name"  #name="ngModel" >
            <div [hidden]="name.valid" class="alert alert-danger">Name is required </div>
        </div>
        
        <div class="form-group">
            <label for="EmailId">Email</label>
            <input type="email" class="form-control" required [(ngModel)]="contact.email" name="email" #email="ngModel">
            <div [hidden]="email.valid" class="alert alert-danger">email is required </div>
        </div>
        
        <button type="submit" class="btn btn-default" [disabled]="!contactForm.form.valid">Save</button>
    </form>
    

Check out the snapshot:

https://i.stack.imgur.com/vOJ5Y.png

Answer №1

This is the code snippet:

styles: [`
   .form-group label { 
     font-weight: bold;
     color: red; 
   }
`]

Check out the style guide.

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

Utilizing Angular Forms for dynamic string validation with the *ngIf directive

I have a challenge where I need to hide forms in a list if they are empty. These forms contain string values. I attempted to use *ngIf but unfortunately, it did not work as expected and empty fields are still visible in the list. How can I address this iss ...

Tips for modifying the color of selected text

Is there a way to change the color of the dropdown text? Currently, it is set to red but initially appears as black. When clicked on, it changes to red. How can I make it so that the color is initially displayed as red? <select> <option style ...

Utilizing CSS3 Pseudo Elements for Styling a Graph

I'm struggling to achieve the desired look of my ancestor chart using an unordered list format. Initially, I borrowed code from CSS3 Family Tree, but found it to be more like an organizational chart rather than a family tree. For testing purposes, he ...

What methods can I implement to prevent my boxes from becoming stretched out?

How can I prevent this box from stretching too much? Here is the code snippet along with the output: CSS: .social { padding-left: 1000px; border: 5px inset black; margin: 4px; width: 100px; } HTML: <div class="social"> <p& ...

Tips for effectively utilizing TypeORM transactions

I'm encountering an issue with transactions in TypeORM. Here's a snippet of the code causing me trouble: const someFunction = async () => { try { await this.entityManager.transaction(async (manager) => { //some opera ...

What is the best way to display information pulled from an API in Angular using ng2 charts?

Hello, can you lend me a hand? I'm currently facing an issue while attempting to display data using ng2 charts in my Angular application. The data is being fetched from a Firebase API, but unfortunately, it's not rendering properly and I can&apos ...

Typescript patterns for creating a modular library design

Transitioning a JavaScript project to TypeScript has been challenging for me, especially when it comes to establishing a solid design pattern for the library's modularity. Main Concept The core functionality of my library is minimal. For instance, i ...

Ways to exit a forEach loop when a specific condition is satisfied and obtain a string or break statement

I'm currently using Angular 14 and have been encountering some issues with a piece of code involving a ternary operator. Despite researching resources like this one and others, I haven't found a solution that works for me. The code in question lo ...

replace the standard arrow key scrolling with a new custom event

Currently, I am in the process of creating a unique scroll box to address my specific needs. The standard html <select> box is not cutting it for me as I require two columns displayed, which I couldn't achieve with a regular <select>. However, I ...

Transitioning the style code from inline to the head of the document disrupts the straightforward JavaScript intended to

As I delve into the world of web development, I encountered a simple issue that has been causing me frustration for the past hour. It involves code to display the border color of a div element using an alert. The code works perfectly fine when the style is ...

Some characters are not compatible with the CSS writing-mode feature

There seems to be an issue with the CSS writing mode not applying correctly to the symbol '№'. Here is an example: <html> <head></head> <body> <p style="writing-mode: vertical-lr;"> Номер № ...

Setting the root position of a div: How can it be done?

Imagine a scenario where a div element is designed to follow the mouse cursor on the screen. This functionality is achieved by manipulating the document's `mousemove` event and adjusting the div's `left` and `top` positions based on the event dat ...

Struggling to solve a never-ending loop problem in a messaging application

I am currently in the process of developing a chat application. During the initialization of the chat page, I am checking for messages and storing them in an array. ngOnInit() { this.messageService.getMessages().doc(`${this.sortItineraries[0] + ...

Creating a compilation of HTML file links using Gulp

Is there a way to utilize Gulp in order to compile a single HTML file containing links to all pages within a specific directory? For instance, if I have two files contact.html titled "Contacts" and faq.html titled "Frequently asked questions" located in t ...

Updating the state in a different component using React and Typescript

The Stackblitz example can be found here I'm attempting to update the useState in one component from another component. Although it seems to work here, it's not functioning properly in my actual application. Here is a snippet of the app.tsx co ...

Using JavaScript variables in a Jinja array

I encountered a frustrating issue that has been causing me some trouble. In my project setup, data is being transferred from Python to the frontend using Jinja in the form of a 2D list. My goal is to loop through this array using a for loop, but I'm ...

Using a timer to make Ajax calls twice on a single webpage

Can multiple ajax calls be made simultaneously on the same page to different receiving div tags? I am struggling to find a solution to this issue. I have a total of 3 pages: a home page, and two PHP pages named status and alert which echo the results. Wi ...

Creating QR codes from raw byte data in TypeScript and Angular

I have developed a basic web application that fetches codes from an endpoint and generates a key, which is then used to create a QR Code. The key is in the form of an Uint8Array that needs to be converted into a QR Code. I am utilizing the angularx-qrcode ...

Handling errors in nested asynchronous functions in an express.js environment

I am currently developing a microservice that sends messages to users for phone number verification. My focus is on the part of the microservice where sending a message with the correct verification code will trigger the addition of the user's phone n ...

Using JavaScript and HTML, create a click event that triggers a drop-down text

Can anyone help me with creating a dropdown feature using JavaScript, HTML, and CSS? I want to be able to click on the name of a project and have information about that project show up. Any suggestions on how I can achieve this? Thanks in advance! ...