The inner HTML functionality in Angular 2 seems to be malfunctioning when dealing with HTML tags

I am facing an issue with an array that includes displayName with HTML tags:

this.topicsList = [
{id: "173", name: "Discussion1", displayName: "Discussion1", status: 1},
{id: "174", name: "discussion123", displayName: "discussion123", status: 1},
{id: "192", name: "erer", displayName: "erer", status: 1},
{id: "184", name: "Hussa Test", displayName: "Hussa Test", status: 1},
{id: "194", name: "Ratheesh^TM^", displayName: "Ratheesh<sup> TM </sup>", status: 1},
{id: "181", name: "test test", displayName: "test test", status: 1},
{id: "189", name: "test topic", displayName: "test topic", status: 1},
{id: "195", name: "test^TM^tdtest", displayName: "test<sup> TM </sup>tdtest", status: 1},
{id: "190", name: "topic test", displayName: "topic test", status: 1},
{id: "193", name: "yu", displayName: "yu", status: 1}
]

My goal is to display the displayName in superscript form while listing and remove the HTML tag. However, when I use [innerHtml] to display the display name list without the functioning HTML tags, it does not work as expected. I need a solution for this problem.

<select class="form-control select-topic" id="select-topic-id"  formControlName="topic" [ngModel]="topicSelected || ''"   (ngModelChange)="topicSelected = $event">
  <option value="">Select Topic</option>
  <option *ngFor="let topic of topicsList" value="{{topic.id}}">{{topic.displayName}}</option>
</select>

I have also tried using [innerHtml], but that did not solve my issue.

<select class="form-control select-topic" id="select-topic-id"  formControlName="topic" [ngModel]="topicSelected || ''" (ngModelChange)="topicSelected = $event">
  <option value="">Select Topic</option>
  <option *ngFor="let topic of topicsList" value="{{topic.id}}"><div  [innerHtml]="topic.displayName"></div></option>
</select>

Answer №1

If you are facing issues with the HTML tag "select", and [innerHTML] is not working properly, leading to the displayName not being superscripted, consider using the "ul" tag for the dropdown instead of the "Select" tag.

[Please take note: You can refer to Bootstrap dropdown for styling options.]

    <div class="dropdown">
          <button class="btn btn-primary dropdown-toggle" type="button" data- toggle="dropdown"><label>Select Manager</label>
          <span class="caret"></span></button>
         <ul class="dropdown-menu">
             <li *ngFor="let topic of topicsList" [innerHTML]="topic.displayName"> </li>
        </ul>
    </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

"Encountered a syntax error while attempting to reference an attribute on an empty object

> "[object Number]" === Object.prototype.toString.call(1) // #1 < true > "[object Number]" === {}.toString.call(1) // #2 < true > {}.toString.call(1) === "[object Number]" // #3 < SyntaxError: Unexpected token ...

Scrolling to a specific element using jQuery after a specified delay has

On my website, I have a page with an autoplaying video located at . My goal is to implement a feature where once the video completes playing after a specific duration, the webpage will automatically scroll down to the text section. This scroll action sho ...

Enhance the interoperability of Babel with Express.js by steering clear of relative

My current approach to imports is as follows: import router from '../../app/routes' Is there a way to avoid using ../../, for example: import router from 'app/routes'? In typescript, I can achieve this with the following configuratio ...

What is the best way to conceal a specific class of DIV within a container, and how can I also hide another DIV within the same container by

I have a DIV class containing around 10 elements within a container. I am looking to implement a feature where these elements are hidden and shown one by one every 15 seconds using jQuery with a smooth fadeOut() effect. Your assistance in achieving this wo ...

The argument type does not match the parameter type partial<>

While attempting to validate my Ionic React form, I encountered an error when calling the validationSchema within the useForm method. The specific error message received is as follows: Argument of type '{ validationSchema: ......' is not assignab ...

Tips on ensuring Angular calls you back once the view is ready

My issue arises when I update a dropdown list on one of my pages and need to trigger a refresh method on this dropdown upon updating the items. Unfortunately, I am unsure how to capture an event for this specific scenario. It seems like enlisting Angular ...

Weird Chrome behaviors with CSS3 animations

I have been working on a CSS3 animation that involves rotating a div with an image in the background. My goal is to have the same animation play at a different speed when the user hovers over the element. Here is the code snippet I have been using: .roc ...

Moving data from one table to another and making changes or removing it

After successfully adding data from one table to another using .click, I encountered an issue. Whenever I utilize the search field in the top table, it clears the appended rows in the bottom table. I am looking for a solution to have these tables generate ...

Transferring an Array from PHP to Javascript

I'm attempting to pass a PHP array so that I can use it in JavaScript. The PHP code I have written is shown below: <?php $link = mysqli_connect("localhost", "root", "password", "database"); /* check connection */ if (mysqli_connect_errn ...

Send data from an AJAX request to a Laravel controller

Here is the code for my ajax request where I am trying to pass values to a controller in Laravel. var deviceid="<?php echo $id; ?>"; var day="<?php echo $day; ?>"; $.ajax({ 'async': false, 'global': false, url ...

Is there a way to optimize app speed in Angular2 by importing CommonModule and RouterModule in a centralized location?

I find myself constantly importing these two modules in almost every component: import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; Is there a way to import them only once in the global app. ...

Utilizing headless Chrome to automatically capture AJAX requests

Chrome officially supports running the browser in headless mode, allowing for programmatic control through the Puppeteer API and/or the CRI library. I've thoroughly explored the documentation but have not discovered a method to programmatically captu ...

Using single quotation marks within a string can cause issues in javascript

I am curious about how to handle single quote marks and other symbols within user-generated text without causing issues with the JavaScript code. Currently, if a user enters a title like "I wouldn't", it breaks the JavaScript functionality. <a cl ...

Is it possible to use the `fill` method to assign a value of type 'number' to a variable of type 'never'?

interface Itype { type: number; name?: string; } function makeEqualArrays(arr1: Itype[], arr2: Itype[]): void { arr2 = arr2.concat([].fill({ type: 2 }, len1 - len2)); } What is the reason for not being able to fill an array with an ob ...

The messageReactionAdd event has suddenly stopped functioning without any explanation

Currently, I am developing a Discord bot that assigns the role "Voteur" to a user when they react to an embed message created by the bot. Everything was functioning perfectly until recently, but for some reason, it has stopped working. The bot successfull ...

The function setCustomValidity() will continue to display even after the form has been successfully filled out

My form is very simple and I am trying to validate it using the required attribute: <form name="form"> <label for="Header">Title</label> <input type="text" class="span5" name="Header" ng-model="Message.header" placeholder="Title" on ...

Which is the better choice for accessing and manipulating JSON files – using Ajax or the Node fs module?

When storing quiz questions using JSON data, should I use vanilla AJAX or Node.js file system to read the file? I am planning to develop a website where users can create quizzes and save them as JSON. I intend to utilize the Node.js fs module to save the ...

Holding onto numerous AJAX requests while disconnected, then dispatching them once the network connection is

I'm working on an application that heavily relies on AJAX requests, requiring the rapid or concurrent sending of multiple calls. The code snippet provided serves as a basic wrapper for sending AJAX POST requests within the app. However, I've enco ...

Using Node and Express to handle form submissions, we can create a POST request that sends data to the server

Despite my ongoing learning journey, I am feeling a bit frustrated as I struggle to find a solution for this particular issue using ES6 Javascript. Currently, I have a straightforward todo-list web-app where everything is managed and displayed through the ...

Is it possible to include a base url for imports in React JS?

Conventional method for adding imports: import Sample from ‘../../../components/signup’ I want to simplify imports by removing the front dots and slashes: import Component from ‘components/signup’ Is there a way to set a base URL for imports to ...