The integration of HTML and CSS using ng-bind-html appears to be malfunctioning

<ion-item ng-bind-html="renderHtml(word[key])">

</ion-item>

When referring to word[key], it represents:

<ul>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ul>

This is the CSS being used:

ul {padding: 1px 10px 1px 20px;list-style-type: upper-roman;}

I am encountering issues with a more intricate structure involving CSS. The styling functions correctly on cordova and react, but when transitioning to Angular (ng), the CSS does not apply as expected. Any advice or insights on what might be causing this discrepancy?

Answer №1

The angular XSS security feature is currently active, as you can see (refer to http://errors.angularjs.org/1.2.23/$sce/unsafe).

There are two methods to solve this issue:

  1. If the HTML content is influenced by or created by the user in any way, it is necessary to include the $sanitize module. For more details, check the provided link.

  2. If the HTML content is exclusively from your end, you can mark it as trusted HTML by using $sce.trustAsHtml. Here is an example:

angular.module('myapp', []).controller('myctrl', function($scope, $sce) {
  $scope.renderHtml = function(html) {
    return html;
  };
  $scope.word = $sce.trustAsHtml('\
<ul>\
  <li>item 1</li>\
  <li> item 2 </li>\
  <li>item 3</li>\
</ul>');
});
ul {padding: 1px 10px 1px 20px;list-style-type: upper-roman;}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp" ng-controller="myctrl">
  <ion-item ng-bind-html="word"></ion-item>
</div>

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

Troubles arise when hovering over the <strong> tag and the <h4> element

While hovering over my h4 tag in the table, everything functions correctly. However, when I hover over the strong tag inside the h4 element, the strong tag inherits the same hover effect as the h4 tag. The structure of each td element within the table is ...

What is the behavior of a variable when it is assigned an object?

When using the post method, the application retrieves an object from the HTML form as shown below: code : app.post("/foo", (req, res)=> { const data = req.body; const itemId = req.body.id; console.log(data); console.log(itemId); }) ...

Keep the music playing by turning the page and using Amplitude.js to continue the song

I have implemented Amplitude.js to play dynamic songs using a server-side php script. My objective is to determine if a song is currently playing, and if so, before navigating away from the page, save the song's index and current position (in percenta ...

Retrieve the duplicated items from an array by comparing two specific properties in JavaScript

I need assistance in identifying and retrieving duplicate objects within an array that share similarities in 2 specific properties. Consider the object structure below: let arry = [ {Level: "A-1", Status: "approved"}, {Level: &q ...

I have received a JSON multi-line string after entering information in a textarea

I've been working on a small social network project where users can create and share posts. However, I encountered an issue with formatting when storing and displaying the posts. When a user enters text with line breaks in the post creation form, it ...

jQuery sidebar with a fixed position

Is there a way to implement a sidebar menu feature using jQuery that reappears on the left as the user scrolls down the page? You can see an example sidebar menu here. ...

How can I utilize the parseFloat feature within my dedicated parseFloat function located in an angular factory?

What is the solution for accessing parseFloat within an angular factory function named parseFloat? angular .module('myApp') .factory('mathService', [MathService]); function MathService() { return { parseFloat: myGl ...

Determine the TR id when a button within a TD element is clicked using JavaScript/jQuery

Currently seeking a method to generate a unique identifier for use as a parameter in a JavaScript function. Specifically interested in extracting the id of the first td element if feasible. <tr id='it'><td id="#nameiron">Jason</td ...

When working with angular.js and angular-sanitize.js, the src attribute is removed from JSON HTML data

I'm new to Angular and I'm really enjoying learning how to work with it. Currently, I have a simple JSON file that contains text structured like this: "gettingstarted":{ "title":"Getting Started", "content":"<img ng-src='i ...

In JQuery, an empty string will be returned if it contains the dollar sign character

In the scenario presented here, the value is retrieved accurately with the exception of when it includes a $ symbol at the beginning (e.g. $25.00), in which case it consistently results in an empty string. HTML: <input type="number" class="form-contro ...

Incorporating AJAX functionality into an existing PHP form

I am currently working on a PHP registration form that validates user inputs using $_POST[] requests. Validating username length (3-20 characters) Checking username availability Ensuring the username matches /^[A-Za-z0-9_]+$/ pattern and more... Instead ...

A function cannot be used with Random Song Loop

Recently delving into the world of JavaScript, I encountered a peculiar issue. When attempting to execute the following code within a function, nothing displays in the console. Yet, after testing it without the function, the expected strings appear as inte ...

What is the best way to ensure consistent Box Overlay Height across multiple boxes?

Is there a way to ensure that overlay box height remains the same even if the text lines are not the same length? Below is a snippet of my code. If you have a solution using jQuery or JS, please provide it. Thank you for your time and effort in trying to h ...

Displaying random divs and subsequently animating them downwards using JavaScript

I am in the process of creating a random appearing div that then falls down. Here is the code I have so far: $(document).ready(function(){ $('#test').animate({top: 80 + '%'},900); }); <div id="test" style="background:#98bf21;heigh ...

Achieve automated zooming out using highcharts-ng through code

Currently, I am using Highcharts-ng as seen on https://github.com/pablojim/highcharts-ng Upon inspecting the source code, I have noticed some interesting functionalities in the directive utilizing scope.$on which I can leverage for broadcasting. One examp ...

Guide on changing the background color of a specific row with pagination

https://i.stack.imgur.com/Q4ggc.png Currently, I'm implementing pagination on an array and need to highlight the rows with a count of zero. The count variable in each row can be accessed using {{x.count}}. I want to customize the background color fo ...

Handling the ng-if condition based on a model that dynamically gets updated through an asynchronous

In my controller, I have implemented a method to update a model asynchronously using $http. To check whether the model is defined or not, I am using a flag. function myController(ModelService){ var vm = this; vm.myModel = ModelService.data; ...

CSS or Coding? Learn how to display items side by side instead of on top of each other

Hey there! I manage a music website that is currently in beta. I'm running into an issue with the way the music results are appearing in the bottom player - they're all stacked on top of each other instead of being listed side by side. I've ...

How to Determine If a String Represents an HTML Tag Using jQuery

Checking if a string is an HTML tag can be tricky. I've tried various methods found on Google, but none have been successful so far: var v = $(string).html() ? 1 : 0; --or---------------------------------------------- var htmlExpr = new RegExp("/^( ...

Storing form data into a database using AngularJS: A comprehensive guide

I am relatively new to working with angular technology. Currently, I am developing an internal tool that allows me to retrieve and update user details such as location, work profile, and mobile number, among others. To achieve this, I have created a form w ...