Adding innerHTML content to tooltip title using typescript in an Angular project

I have encountered an issue while trying to display HTML content inside a tooltip element's title attribute. The HTML content is not rendering as expected and appears as text instead.

Let me outline the structure of my Angular project:

library.comp.html: This file contains my component code. library.comp.ts: Here, I write my TypeScript code for the component.

demo.comp.html: This is where I call my component from the library. demo.comp.ts: In this file, I manipulate the component contents and render them in demo.comp.html.

Here's a snippet of the code in my Angular project:

library.comp.html

   kendoTooltip
   [id]="tooltipConfig.id!"
   [tooltipTemplate]="tooltipConfig.tooltipTemplate!"
   [title]="tooltipConfig.title!"
   [innerHTML]="tooltipConfig.text!"
   [closable]="tooltipConfig.closable!"
   [position]="tooltipConfig.position!"
   [tooltipWidth]="tooltipConfig.tooltipWidth!"
   [showOn]="tooltipConfig.showOn!"
  ></div>

library.comp.ts

export class AuraTooltipComponent implements OnInit {

  @Input() tooltipConfig!: TooltipConfig;

demo.comp.html

<aura-tooltip  [tooltipConfig]="tooltipConfig_basic"></aura-tooltip>

demo.comp.ts

this.tooltipConfig_basic = {
      title: "<h1>Click</h1> the button to show the tooltip with",
      text: 'Tooltip1',
      closable: true,
      position: 'right',
      tooltipWidth: 400,
      id:'tooltip2'

    }

**Output : **

Current Output

https://i.stack.imgur.com/lzwuG.png

**Expected Output : **

The desired result is to have the tags rendered instead of appearing as text within the tooltip title content.

As described above, I faced difficulties in rendering the HTML content properly between the component library and the demo.html. Any assistance on this matter would be highly appreciated.

Answer №1

If you're curious about the Kendo Popover, it is described as "a popup with rich content that is related to a single or multiple UI elements" in the official documentation. This feature comes with special directives:

  • kendoPopoverTitleTemplate
  • kendoPopoverBodyTemplate
  • kendoPopoverActionsTemplate

Here is an example of how to use it (taken from the demo in the documentation):

<button
  kendoPopoverAnchor
  [popover]="myPopover"
  kendoButton
  themeColor="primary"
  [style.marginLeft.px]="200"
>
  Show Waffles Recipe
</button>

<kendo-popover #myPopover [width]="300" position="bottom">
  <ng-template kendoPopoverTitleTemplate>
    <div class="popover-title">Pumpkin Waffles</div>
  </ng-template>

  <ng-template kendoPopoverBodyTemplate>
    <img class="picture" [src]="wafflesImg" />
    <div>{{ wafflesRecipe }}</div>
  </ng-template>

  <ng-template kendoPopoverActionsTemplate>
    <button kendoButton fillMode="flat" themeColor="primary">
      <span class="k-icon k-i-heart-outline"></span>
      Like
    </button>
  </ng-template>
</kendo-popover>

By following this structure, you will achieve a design similar to the one shown in this image: https://i.stack.imgur.com/H9VUc.png

To delve deeper into the Kendo Popover functionality, visit their site. For information specifically on templates, check out this link.

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

Potential absence of the object has been detected after performing object verification

I encountered an issue with the following error message: Object is possibly 'undefined'.ts(2532) This is what my configuration looks like: export interface IDataColumns { name: string; label: string; display: string; empty: boolean; fi ...

Exploring the method to retrieve a dynamically added property in Typescript

My React Component Loader receives certain props. The contentAlign property is only available when the local property exists and its value is 'relative'. I am encountering an error when trying to include contentAlign in the props, and I cannot ...

Angular 14 troubleshooting: Issues with using getRawValue() in IndexOf function

In this scenario, I have a straightforward Person interface defined as: import { FormArray, FormControl, FormGroup } from '@angular/forms'; import { Address } from './address'; export class Person { id: FormControl<number>; n ...

Want to understand the concept of "template" within the @Component decorator in Angular 7?

I am curious about the purpose of the "template" attribute within the @Component decorator. I understand how "templateURL" functions, but I have yet to experiment with including HTML directly inside a component. https://i.stack.imgur.com/W5LiB.png What a ...

Navigating to the Login page in Angular 13

<app-navbar></app-navbar> <div class = "app-body"> <div class="app-sidebar"> <app-sidebar></app-sidebar> </div> <div class="app-feed"> <router-outlet name="main& ...

Leverage functionalities from the rxjs npm package within an Angular application without the need for npm install

In the midst of updating my Angular 4 application to use rxjs version 6.3+, I discovered that many changes in rxjs are causing issues with my existing codebase. One of the new features we need to implement requires this update, but it's proving to be ...

Can Angular's change detection be triggered by a change in @Input?

As of now, I am immersing myself in guides and tutorials on Angular's change detection. There are some statements that are quite perplexing to me. Therefore, I am seeking confirmation or clarification. The default Change Detection is activated "every ...

MUI version 5 with styled-components and ListItemButton: The specified property 'to'/'component' is not recognized

While transitioning from MUI v4 to v5, I encountered a hurdle: in v4, I utilized makeStyles(), but now aim to fully switch to styled(). Unfortunately, I am struggling to get Typescript to recognize a styled(ListItemButton)(...) with to= and component= attr ...

Is there a counterpart to ES6 "Sets" in TypeScript?

I am looking to extract all the distinct properties from an array of objects. This can be done efficiently in ES6 using the spread operator along with the Set object, as shown below: var arr = [ {foo:1, bar:2}, {foo:2, bar:3}, {foo:3, bar:3} ] const un ...

Is it possible to modify the content of an element with a click event in Angular/HTML?

How can I implement a feature in my mat-accordion using mat-expansion-panels where the text becomes underlined when the panels are clicked? I want the title to be underlined when the panels are open and for the underline to disappear when they are closed ...

The element 'Component' is not eligible to be utilized as a JSX component (typed layout)

I encountered a type error while working with the following code snippet: {getLayout(<Component {...pageProps} />)} The error message states that 'Component' cannot be used as a JSX component. This is because its element type 'Compo ...

Angular Material calendar tool customization for designated input

Is it possible to individually control the format of input for a datepicker without affecting the format for the entire module? <input matInput [matDatepicker]="dp" [formControl]="date" [format]="'DD/MM/YYYY'"> <-- Can this be done? < ...

The "number" input type is functioning correctly on Chrome, but on Firefox, it is accepting characters other than numbers

While developing in Angular, I encountered a challenge where I needed to create an input that only accepts numeric characters. Initially, I tried using type="number" which worked perfectly in Google Chrome but surprisingly allowed non-numeric characters ...

The InAppBrowser seems to have trouble loading pages with cookies when I attempt to navigate back using the hardware back button

In my Ionic/Angular application, I utilize the InAppBrowser plugin to access a web application for my company. The InAppBrowser generally functions properly; however, there is an issue with a cookie within the web application that controls filters for cert ...

When a form contains a ViewChild element, changes to the ViewChild element do not automatically mark the

Let's set the stage: MainComponent.html <form #someForm > <input type="text" name="title" [(ngModel)]="mainVar" /> <child-component /> <input type="submit" [disabled]="someForm.form.pristine" /> </form> ChildComp ...

Search input in real-time

I am in the process of implementing a live search input feature in Ionic 3 within a form group. Within my TypeScript file, I have the following code: getSubElements(selectedValue) { if(selectedValue){ this.VisitesProvider.getEcolesLi ...

"Unsuccessful API request leads to empty ngFor loop due to ngIf condition not being

I have been struggling to display the fetched data in my Angular 6 project. I have tried using ngIf and ngFor but nothing seems to work. My goal is to show data from movies on the HTML page, but for some reason, the data appears to be empty. Despite tryin ...

Gradle synchronization in IntelliJ causing missing folders in WAR Artifact

Currently, I am working on a Spring MVC application that incorporates TypeScript. The TypeScript code is transpiled using a Gradle task from the directory src/main/ts to build/ts. Subsequently, the resulting JavaScript files are added to the WAR file usin ...

Errors in TypeScript Compiler for using react-bootstrap in SPFx project

After setting up an SPFX Project with Yeoman generator and including react-bootstrap as a dependency, I encountered errors when using react-bootstrap components and running gulp serve. The error messages are as follows; does anyone have any solutions to ...

Adjust the height, width, and color of the "kendo-switch" widget

I am looking to customize the height, width, and color of the "kendo-switch" component. I attempted to modify the element's style directly, but it did not have the desired effect. What would be the most effective approach for achieving this customiza ...