HTML textarea fails to recognize inline styles

My journey with JHipster began recently when I embarked on my first project. Two entities were created, one of which resembles a blog. This particular blog entity has a content attribute that interacts with a textarea. In my blogs.html file, I allowed the use of HTML tags in my textarea by including:

<div ng-bind-html="topic.content"></div>

This setup seems to work seamlessly as intended. I am able to define HTML tags within the textarea and see them interpreted correctly.

However, things took a turn when I attempted to style the newly formed attributes. A basic div with inline styles like:

<div style="font-size:100px"> Test</div>

The above snippet is being recognized as HTML, but the styling aspect is being disregarded. I even tried using ng-style instead:

 <div ng-style="font-size:100px"> Test</div>

Unfortunately, this approach did not yield the desired results either. I also experimented with adding the !important flag to no avail.

Providing specific code snippets may be challenging as JHipster generated my entities autonomously. It's unclear whether any scripts are overriding my styles or prohibiting the use of style tags altogether. Nevertheless, I have captured some images that might help illustrate the issue:

This image shows the user inputting content into the textarea https://i.sstatic.net/40ENH.png

Here is how the final output appears, where the "Test" text should ideally be colored:

https://i.sstatic.net/dWzHr.png

Lastly, here is a representation of how my browser is rendering the attribute:

https://i.sstatic.net/5RVEo.png

Your assistance in resolving this matter would be greatly appreciated!

Answer №1

It seems like the sanitizer is removing the style tag...

To fix this issue, you can include the $sce service in your controller and assign the trustAsHtml function to the view:

$scope.trustAsHtml = function(string) {
    return $sce.trustAsHtml(string);
};

Afterward, you can implement the following code:

<div ng-bind-html="trustAsHtml(topic.content)"></div>

This should resolve the problem, but it's important to ensure that topic.content is sourced from a trusted origin (not user input) to prevent injection attacks.

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

Having trouble with jQuery modal not adjusting its height properly

I am a jquery modal popup newcomer. I can open the modal when clicking on the hyperlink, but I'm having trouble with the height setting. Despite my attempts and searches online, I couldn't figure it out. When trying to post a question about the & ...

Is it possible to recognize when the mouse button is held down and the cursor is outside the viewport by using mouseleave detection?

Is there a way to detect when a user moves the mouse outside of the view-port, even if they are holding down the mouse button (for example, if the mouse is on the browser address bar)? In the code below, I am currently using mouseout and mouseleave to det ...

Utilize jQuery and JSP (or PHP) to showcase detailed information about a specific item when a user clicks on it within an HTML page

For my upcoming college project, I am tasked with developing a movie library. The main page of the library will feature various movie posters. Upon clicking on a poster, users will be directed to a dedicated page displaying detailed information about the ...

Unable to assign unique identifiers to elements within a user interface framework

I am having difficulty assigning an id to components. Scenario 1: - Trying to assign an id to an HTML component. <h1 id="demo-h1">Demo Heading</h1> Assigning id to HTML component Scenario 2: - Attempting to assign an id to a componen ...

Ways to modify font color in JavaScript "type"

Recently, I came across a fascinating technique where by simply refreshing the page, the text changes sentences. I managed to implement the code successfully, however, I am having trouble changing the color, size, and alignment of the text. <script type ...

Pop-up confirmation dialog in JQuery following an AJAX request

In order to validate on the server side whether a person with a specific registration number already exists in the database, I have implemented a process. If the person is found registered, the program flow continues as usual. However, if the number is not ...

Creating an HTML table from JSON data

Struggling to display real-time statistics in a table on an HTML web page? I have the data in JSON format, but can't seem to get it right. You can find the data at: I attempted the following code snippet, but it was not successful: <!DOCTYPE htm ...

the contents exceed the boundaries

As I work on creating a page to display a list of books, I am facing an issue where the content sometimes overflows out of the book-info box. This usually happens when a book's title is excessively long and goes beyond the set height of 140px. I am se ...

Golang template's nested ranges

Being fairly new to this, I could use a little assistance. I have these two structs: type School struct { ID string Name string Students []Student } type Student struct { ID string Name string } M ...

Uncovering the Power of Shadow DOM within HTML

Lately, I've noticed a lot of buzz surrounding Shadow DOM. During a video I watched about the launch of Angular 2, the speaker kept mentioning Shadow DOM without much explanation. Can someone clarify what exactly Shadow DOM refers to? ...

Learn how to create a button that will only submit a value when clicked using Node.js and EJS

Currently in my ejs file, I have a button that sends a value to app.js instantly when the program runs. However, I want it to only submit the value when clicked by the user. <% notesArray.forEach((note,i) =>{ %> <div class="note"> ...

Sharing information between different components in React can be done using props, context, or a

When attempting to edit by clicking, the parent information is taken instead of creating a new VI. I was able to achieve this with angular dialog but I am unsure how to do it with components. This is done using dialog: <div class="dropdown-menu-item" ...

Stop angular schema form's destroyStrategy from deleting any data

After upgrading my Angular app from version 0.8.2 to 0.8.3 of Angular Schema Form (ASF), a significant bug emerged. The application features multi-page forms that utilize prev/next buttons for navigation. A condition is implemented to display only relevan ...

React Array Not Behaving Properly When Checkbox Unchecked and Item Removed

When using my React Table, I encountered an issue with checkboxes. Each time I check a box, I aim to add the corresponding Id to an empty array and remove it when unchecked. However, the current implementation is not functioning as expected. On the first c ...

The jQuery countdown plugin is yielding some unexpected outcomes

Feeling a bit rushed for time, so I thought I'd ask here. The date is currently 2012-10-06 and I'm attempting to implement a jQuery plugin called "jquery.countdown.js". It seems pretty straightforward. Can anyone point out what I might be doing i ...

Enhance the functionality of the Angular Tabs directive

I have developed a tab directive in Angular using jQuery. Despite everything appearing correct, I am unable to identify any issues with it. Could someone please review my code and point out any mistakes? I believe my Angular directive relies too hea ...

A rightward sliding submenu that appears upon clicking a button

I have a vision of creating an admin control panel for my website, featuring a set of buttons. I envision that when one of the buttons is clicked, the corresponding sub-menu will appear alongside it. For instance, if "My Account" is selected, its sub-menu ...

How can I identify the moment when an AngularJS route controller is no longer in scope?

Currently, I have a controller set up to poll the server at regular intervals using $timeout. The issue arises when the route changes - I need to stop the polling and then restart it once the original route is accessed again. If anyone has any suggestions ...

Issue with SVG marker not functioning properly when hovered over

I am having an issue with buttons containing SVG elements, here is an example code snippet: <button> Checkout <ArrowSvg /> </button> The ArrowSvg component looks like this (with the line having a class of "svg-line"): <svg fill=&quo ...

How to use jQuery to remove an empty <ul> tag

Here is the code snippet I am working with: ` <ul id="jsddm"> <li><a href="Default.aspx"> Menu</a> <ul style="visibility: hidden;" ...