The innerHTML property is unable to retrieve the class defined in the .scss file within the component

The Angular 9 code is ready to go. I want to display the default paragraph on the page. However, I'm unable to apply the .scss class in the component.

.HTML:

<div [innerHTML]="htmlCode"></div>

.TS:

htmlCode: string = "<p class='newClass'>TEST</p><br>TEST<br>";

.SCSS:

.newClass{
  background-color: red;
}

Answer №1

To implement custom styles in Angular using SCSS, add the following code snippet:

@Component({
  ...
  styles: ['
    .customStyle{
       font-size: 16px;
       color: blue;
    }
  '],
  encapsulation: ViewEncapsulation.None,
})

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

What could be causing my bootstrap navbar-toggler button to be unresponsive?

I have created a responsive navbar that displays items on a large screen and a toggle button on a small screen to reveal the navabar items. However, I am facing an issue where the toggle button does not work when clicked on a small screen. Any ideas on wha ...

Retrieve the values from input elements that have been created dynamically

I wrote some JavaScript code to generate dynamic input elements. Here's an example: while(count<n-2){ if(dataArray[count+1]=='String') var txt = "Argument:"+(count+1)+", Prefix: <input type=\"text\" name=\"prefix[ ...

Press the Relay button to initiate the ASP.NET File Upload functionality

Within an ASP.NET C# website, I have incorporated an input that allows the user to upload a file to the server. To address the limitation of not being able to style an input of type=file, I devised a visually styled div that mirrors the appearance of the i ...

Retrieving information from the GitHub API using Angular 4

I attempted to retrieve my last commit from GitHub using the GitHub API, but encountered an error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays." I ...

What might be the reason behind Chrome occasionally not updating the page when I resize the browser window?

Currently, I am in the process of developing a responsive design site prototype. Everything is going smoothly except for one peculiar issue that only seems to occur in Chrome. Sometimes, when expanding the window, the browser appears to get stuck between s ...

Inquiries about the jQuery Button Timer

Currently experimenting with jQuery to create a timer. Everything seems to be in place and the Stop Timer button is functioning properly. However, I'm facing issues with the Start Timer and Reset Timer buttons as they are not working as expected. Seek ...

Convert JSON data into an HTML table using JavaScript without displaying the final result

I need help troubleshooting my JavaScript code that is supposed to populate an HTML table with data from a JSON file. However, the table remains empty and I can't figure out why. Sample JSON Data [{"User_Name":"John Doe","score":"10","team":"1"}, { ...

Can anyone recommend the best method for pinpointing the exact building the user is currently in - utilizing HTML5 geolocation or creating a customized map?

In the process of developing a web application using Google App Engine and Python, I have come across information suggesting that HTML5 geolocation provides more accurate results compared to IP geolocation. However, I am curious if this level of precisio ...

Token is not being generated post login using angular-oauth2-oidc

I'm currently working on integrating the OAuth2 library (angular-oauth2-oidc) for authentication with AWS Cognito. Upon launching my application, I successfully land on the default login page of AWS Cognito. However, after entering my login credential ...

Creating a Dynamic 4-Column Website Design with HTML and CSS Div Elements

I am struggling with creating a simple website layout. Here are some images of the design I'm trying to achieve, along with my code. https://i.sstatic.net/lbhvG.png https://i.sstatic.net/wc8wr.png My question is whether each column (4 in total) shou ...

Error: Trying to access the `push` property of an undefined value is causing an issue

Issues with using the push method in TypeScript have arisen. Here are the details: Below is the code snippet for the reservation modal component: guestArray=[1, 2, 3, 4, 5, 6]; guests: number; isDateTime: boolean = false; constructor(private params: Mo ...

Unraveling stray text in Python BeautifulSoup4

<li><a class="atc-group atc-group-active" href="" data-url="/atc-kodlari/1"> <i class="fa fa-lg fa-pulse fa-spinner atc-group-loading" style="margin-right: 5px; display: none;"></i> ...

Looking to achieve a stretch-auto-auto column layout in Bootstrap 4 - how can this be done?

Essentially, I am looking for something similar to this: https://i.sstatic.net/ss3Ir.png Can this layout be achieved using columns instead of floats? <div class="clearfix"> <div class="float-left"><button class="rounded btn btn-outline ...

As I adjust the size of my browser, my website dynamically resizes to match

Recently, I created a website but encountered a bug where the website resizes when I resize my browser. This issue has been observed in Firefox (10.0.2), Chrome (16.0.912.77), and Opera (11.60) browsers. Interestingly, when testing other websites such as ...

Utilizing Dynamic Components and the Event Emitter Feature in Angular Version 5

As a newcomer to Angular, I am currently grappling with the concept of dynamic components within my project. Specifically, I am working on implementing functionality where a user can select a row in a component and then click a button to open a modal (cont ...

Develop personalized validation modules for the dynamically included form elements within Angular

https://i.sstatic.net/3nI8U.jpgI am facing a challenge in my angular development journey where I need to implement validation for dynamically added rows. Using template-driven forms, I have two fields - ValidFrom and ValidTo, along with an array of blacko ...

What is causing my password generator to reveal the password prematurely, before I even press the button?

I'm encountering an issue with the function where it generates a new string every time I refresh the browser. What I really want is for the string to appear only when I click the button, and then generate a new one each time the button is clicked. Any ...

Adding and sorting div elements from an external HTML file

Greetings everyone, I have recently delved into the world of coding and am currently working on a project for my course to streamline access to information and data in my daily life. So far, I have created a single HTML file and two additional external HT ...

Position the image, text, and header within a box in uniform alignment

Currently, I am working on a design that includes an image, a header, and some text inside a box. However, I am facing an issue with aligning the header so that it appears above the rest of the text. The layout is not turning out as expected. https://i.ss ...

Display the full image size when the mouse is hovered over

I currently have two links for a single image. One link is a thumbnail displayed on the screen, while the other link leads to the full-size version of the same image. Is there a way I can implement a code that will darken the screen and display only the f ...