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

This error is being thrown because the element has an implicit 'any' type due to the fact that a 'string' type expression cannot be used to index the 'Users' type

As I attempt to extract data from a json file and create an HTML table, certain sections of the code are functioning correctly while others are displaying index errors. All relevant files are provided below. This issue pertains to Angular. This is my json ...

Typescript does not produce unused members

Having an issue with the JS code that TypeScript compiler is generating. Here's an example class: // Class export class UserDTO { Id: number; FirstName: string; LastName: string; DateOfBirth: Date; getFullName(): string { ...

Can a function interface be implemented in TypeScript successfully?

I am interested in implementing this functionality: class MyFunc extends ((s: string) => boolean) { ... } This would allow an instance of MyFunc to act as a function that takes a string input and returns a boolean value, like so: const f = new MyFunc ...

The VSCode's intellisense for Angular Material fails to function effectively

In the midst of my project on Angular version 13, I have successfully installed Angular Material using the command below: ng add @angular/material The package has been properly included in the node_modules folder. However, when working with TypeScript ...

The most effective method for transferring a JavaScript object between a TypeScript frontend and a Node.js backend

I need some advice on how to effectively share a JavaScript object between my Angular2 with Typescript frontend and NodeJS backend in an application I'm working on. Currently, I am using a .d.ts file for the frontend and adding a module.exports in the ...

Having trouble installing Bootstrap using the `npm i bootstrap` command? It seems like the

The npm i bootstrap command is not working when trying to install Bootstrap. Nothing is being added to the packages.json file or node_modules directory. Here are the dependencies listed in the package.json file: "dependencies": { "@angu ...

Removing outlines on <p> <a> or <div> elements with Ionic and Angular seems to be a challenging task

Hey there, I’m currently working on my application which includes a login page. I've implemented a “Forgotten password ?” link, but no matter what I try, like using .class and :focus {outline: none}, I still see a yellow square around the item. ...

Retrieve data from Ionic storage

Need help with Ionic storage value retrieval. Why is GET2 executing before storage.get? My brain needs a tune-up, please assist. public storageGet(key: string){ var uid = 0; this.storage.get(key).then((val) => { console.log('GET1: ' + key + ...

React TypeScript Context - problem with iterating through object

Can someone please help me with an error I am encountering while trying to map an object in my code? I have been stuck on this problem for hours and despite my efforts, I cannot figure out what is causing the issue. Error: const categoriesMap: { item: ...

In Typescript, a function that is declared with a type other than 'void' or 'any' is required to have a return value

I'm a beginner in Angular2/Typescript and I am encountering an error while trying to compile my project: An error is showing: A function that has a declared type other than 'void' or 'any' must return a value. Here is the code sn ...

The HTML template remains unchanged unless explicitly triggering detectChanges() with change detection set to onpush

In my Angular component, I am utilizing change detection on push. The component includes an input that gets modified by the component when the route changes. However, I noticed that simply assigning a new reference to the input and making modifications d ...

Creating a rotating circle in CSS with ion-slides: A step-by-step guide

Hello, I am attempting to develop a circular object that will rotate in the direction it is dragged. Within this circle, there are elements positioned along the border so that these elements also spin accordingly. To illustrate, below are the specific elem ...

Routing in Angular app breaks down after selecting a single route

I'm new to Angular and currently working with the Router module. I have a Servers component with 3 servers, and clicking on each server should open the individual server's component on the same page. However, I've encountered an issue where ...

Integrate a service component into another service component by utilizing module exports

After diving into the nestjs docs and exploring hierarchical injection, I found myself struggling to properly implement it within my project. Currently, I have two crucial modules at play. AuthModule is responsible for importing the UserModule, which conta ...

When converting a .ts file to a .js file using the webpack command, lengthy comments are automatically appended at the end of

As a backend developer, I recently delved into UI technologies and experimented with converting TypeScript files (.ts) to JavaScript files (.js) using the webpack command. While the conversion works well, the generated .js file includes lengthy comments at ...

Transforming an Angular 11 HTML template into Angular code

After attempting to transfer the Porto Admin HTML template to Angular, I encountered some issues. When including the CSS and JS dependencies in the project, everything worked fine with all the HTML code in index.html. However, when I moved the code to app. ...

Absence of property persists despite the use of null coalescing and optional chaining

Having some trouble with a piece of code that utilizes optional chaining and null coalescing. Despite this, I am confused as to why it is still flagging an error about the property not existing. See image below for more details: The error message display ...

How can I receive the response from a GET request using React Query? I am currently only able to get the response

I have created a search component where I input a name in the request, receive a response, and display it immediately. However, after the first input submit, I get undefined in response. Only after the second submit do I get the desired response. The tec ...

Having trouble importing SVG as a React component in Next.js

I initially developed a project using create-react-app with Typescript, but later I was tasked with integrating next.js into it. Unfortunately, this caused some SVGs throughout the application to break. To resolve this issue, I implemented the following pa ...

Error: Uncaught TypeError - The function boss.SetBelongToClan is not defined

Currently, I am faced with an issue while working on a typescript and sequelize project within an express application. The problem arises when trying to create a type-safe interface for utilizing the associate function. Within my Instance interface, there ...