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

Enhance your Next.js routing by appending to a slug/url using the <Link> component

In my Next.js project, I have organized my files in a folder-based structure like this: /dashboard/[appid]/users/[userid]/user_info.tsx When using href={"user_info"} with the built-in Next.js component on a user page, I expect the URL to dynamic ...

In order to effectively manage the output of these loaders, it may be necessary to incorporate an extra loader. This can be achieved by using the

I'm currently working with react typescript and trying to implement a time zone picker using a select component. I attempted to utilize the npm package react-timezone-select, but encountered some console errors: index.js:1 ./node_modules/react-timezo ...

tips for remaining in modal window post form submission

I have a form within a modal window. I am using ajax to load content in the same modal window, but the issue is that it redirects to the main page after submitting the form. How can I ensure that the modal window stays open even after the form submission? ...

update angular component after deleting an item

After deleting a contact in the table, I'm trying to refresh my contact list page but it's not working. Any suggestions? This is the list of contacts in the contact.component.ts file Swal.fire({ title: 'Do you want to delete this contac ...

Encountering an issue during the initialization of the Google Passportjs

I recently made the switch from JavaScript to TypeScript in my server project and I'm currently tidying up some code. I decided to combine my Google Passport OAuth stuff and login routes into a single file, but it seems like I've broken something ...

Tips on expanding an interface of a subclass

Using the latest versions of TypeScript and ReactJS together has presented a challenge when it comes to extending classes and their interfaces. To address this issue for several form elements that share common validation methods, I have created a BaseComp ...

Ensuring Consistent Item Widths in a Loop using JavaScript or jQuery

In my code, I created a function that dynamically adjusts the width of elements in a loop to match the widest element among them. // Function: Match width var _so20170704_match_width = function( item ) { var max_item_width = 0; item.each(function ...

What is the best way to fetch and convert information from an API to display on a website?

I am encountering an issue while trying to retrieve data from an API. Below is my code with a fabricated access code. $(function () { var $data = ('#data'); $.ajax({ type: 'GET', url: 'http://api.openweathe ...

Within an Angular test scenario, execute a static method from a service that triggers an HTTP get request to fetch stored JSON data. This data is then retrieved and returned back to the service

Currently, I am facing a challenge in my Angular test case where I am trying to load JSON data via an HTTP call. The issue arises when a static method is called from a service spec file named "url-service.spec" to another service named "load-json.service. ...

What is the best way to choose every single element on the webpage excluding a specific element along with all of its children?

Is there a way to hide all content on a page except for a specific element and its children using CSS? I've been exploring the :not selector, but I'm struggling to make it work with the * selector. :not(.list-app) { display: none; } :not(. ...

Transferring information to a complex and deeply embedded Angular component

In my current component structure, A includes B, B includes C, and C includes D. I am looking to transfer data from the topmost component (A) to the one at the bottom of the hierarchy (D). Should I utilize data binding in HTML templates, which would requ ...

Issue with md-stretch-tabs in Angular-Material causing a problem

I am in the process of developing an Angular-based application. ISSUE: I included md-stretch-tabs in my md-tabs element, but when I switch to tab#2, the tab retracts as if there is not enough space to flex. Is this problem related to dependencies or the c ...

Angular: handling HTTP errors gracefully in the chain of operations

I am facing an issue where I need to treat specific HTTP error codes as non-errors and handle their responses normally. To achieve this, I implemented an HttpInterceptor to catch 500 status codes and return the original response that Angular stores in erro ...

Top div click causes bottom div to slide

I'm currently working on a project that involves using CSS and jQuery, but I've encountered an issue that I haven't been able to solve. Here is the demo link: . When the second div is clicked, why does the third div slide? How can this prob ...

Struggling with setting up the onChange function in a Next.js application

After successfully writing and testing the code here, I encountered an error preventing me from building it. Please review the code for any issues. I am attempting to set onChange to handle user input in a text field. Currently using onChange={onChange}, ...

Tips for altering the color of the MUI table sort label icon:

Does anyone know how to change the color of the table sort label icon from gray to red? I am having trouble figuring it out. Any recommendations or suggestions would be greatly appreciated. Here is the code I have been trying to work with: <TableSortL ...

How can a method be called from a sibling component in Angular when it is bound through the <router-outlet>?

In my current project, I have implemented an application that utilizes HTTP calls to retrieve data from an API endpoint and then displays it on the screen. This app serves as a basic ToDo list where users can add items, view all items, delete items, and pe ...

Avoid triggering the onClick event on specific elements in React by utilizing event delegation or conditional rendering

programming environment react.js typescript next.js How can I prevent the onClick process from being triggered when the span tag is pressed? What is the best approach? return ( <div className="padding-16 flex gap-5 flex-container" ...

Enhancing a Given Interface with TypeScript Generics

I am looking to implement generics in an Angular service so that users can input an array of any interface/class/type they desire, with the stipulation that the type must extend an interface provided by the service. It may sound complex, but here's a ...

django was unable to interpret the remainder: 'css/materialize.min.css' from 'css/materialize.min.css'

In following a tutorial, I am adding a chat bot UI that is embedded in Django. The file structure looks like this: . ├── db.sqlite3 ├── installDjango.sh ├── manage.py ├── rasadjango │ ├── asgi.py │ ├── __init__.p ...