Is it possible to display a Web Component within Angular?

This demonstration showcases the integration of a web component called fs-image within the HelloComponent's rendered HTML.

import { Component, Input } from "@angular/core";
import { DomSanitizer, SafeHtml } from "@angular/platform-browser";

@Component({
  selector: "hello",
  template: `
    <div [innerHTML]="safeHTML"></div>
  `,
  styles: [
    `
      h1 {
        font-family: Lato;
      }
    `
  ]
})
export class HelloComponent {
  constructor(private dm: DomSanitizer) {
    this.safeHTML = this.dm.bypassSecurityTrustHtml(this.html);
  }
  @Input() name: string;
  safeHTML: SafeHtml;

  html: string = `
  <h1> Web Component Test</h1>
  <fs-image url="https://fireflysemantics.github.io/i/developer/instant-html-vscode.png"></fs-image>
  `;
}


The html property which contains the web component is sanitized using

DomSanitizer.bypassSecurityTrustHtml
to prevent Angular from removing the custom element.

However, despite including the custom component in the markup, it does not render as intended. The expected rendering can be seen here: https://stackblitz.com/edit/typescript-fs-image-demo

To include the web component, a CDN declaration is added in the head section:

<head>
  <script src="https://unpkg.com/@fireflysemantics/fs-image"></script>
</head>

Do you have any suggestions on why the web component is not rendering?

Answer №1

Understood - I see that the fs-image element is set to use 100% for both width and height, which required me to place it within a container with a specified height.

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

In JavaScript code, a function is mistakenly updating a cell value in a table to NaN instead of the expected

Here is my custom JavaScript function: function calculateWeight(reps, weight) { var hundredPercent = Math.ceil(weight / (1.0278 - (0.0278 * reps))); var ninetyFivePercent = Math.ceil(hundredPercent * 0.95); var cellX = document.getElementById( ...

Ways to reference an Array variable using a string in JavaScript

const EleList = [1,2,3] name = 'Ele' const render = function(type){ window[type + 'List'].forEach(function(value){ console.log("LOL") }); render('Ele') I'm trying to dynamically call an array using a string. Wh ...

The function .load callback was triggered on five separate occasions

I'm currently working with the code below and I have a feeling that I'm overlooking something important but just can't seem to figure it out. Basically, when the user clicks a button, a fragment of the page is loaded. Once this loading is s ...

How can I use the same popup button to open a different link in a new tab?

I have a situation where I am using a button to trigger an ajax html popup. What I want is for the same button, when clicked, to open another page in a new tab. Any assistance would be greatly appreciated. Below is the HTML code I am currently using: < ...

Utilizing TypeScript interfaces for seamless communication between client and server-side Mongoose models

I am encountering difficulties while attempting to share base interfaces between the client code and server code. The issue arises when trying to use these interfaces to create data models in mongoose. The specific problem I am facing revolves around acce ...

What makes jQuery objects inherently one-of-a-kind?

After researching jQuery objects on this website, it was mentioned that each jQuery object is distinct, even when created with the same selector or containing references to the exact same DOM elements. For instance, the comparison below would result in fa ...

Implementing GRIDFS for mp3 storage in a meteor application

Being a novice in the world of meteor, I am currently working on defining an mp3 collection and then uploading music to it from the admin page. The packages that are installed include: cfs:standard-packages cfs:gridfs cfs:filesystem 1) I have successful ...

What is the best way to achieve this particular grid layout using html and css?

I have a CSS grid of icons and I am trying to create a divider between each cell that fades in opacity towards the edges, similar to an airbrush effect. However, I want the cells themselves to remain transparent so that the background pattern is still visi ...

Having trouble with innerHTML.value functionality?

Recently, I've been delving into creating a JavaScript program that fetches Wikipedia search results. Initially, everything seemed to be working fine as I was able to display the searched item using the alert() method. However, for some reason, it now ...

What should be included in version control after installing NativeBase in a React Native project?

After starting a react-native project, I decided to experiment with the native-base library. Upon installing it and its dependencies, I noticed changes in both the ios and android folders. This prompted me to question whether or not I should include these ...

Trigger an input file click automatically using vanilla JavaScript with an AJAX request in Google Chrome

Currently, my webapp operates in a way that every button click triggers an ajax request to the server. The server then validates and sends JavaScript code back to the client. Unfortunately, the framework I am using does not allow me to incorporate jQuery a ...

Utilize Vue.js and Axios to showcase information retrieved from a JSON API

Here is the code I have for a Vue.js application I'm developing. The data retrieval works well, but I'm struggling to display it on the front-end. If anyone could provide assistance, it would be greatly appreciated. data() { return { ...

Using AngularJS to Send Arrays of Objects to PHP

Currently, I am adapting to using AngularJS ng-resource, however, I am encountering an issue with serializing an array. The ng-resource implementation that I am working with is structured as follows: app.factory('MyModel', ['$resource' ...

Creating an Array in AngularJS with ng-model and submitting it with jQuery: A comprehensive guide

I am struggling to submit an array of values using jQuery and AngularJS. Whenever I click the submit button, only the first array value is being retrieved. How can I get all array values using ng-model? Here is a link to all my code: https://jsfiddle.net/r ...

Creating a structure object in a Laravel controller for implementing Vue.js autocomplete functionality

I am currently facing an issue with my autocomplete feature not displaying options correctly. To start off, I am fetching hard coded data from my controller and passing it through an axios call: searchController.php $searchResults = [ 0 => (ob ...

I'm attempting to make a specific element in an array shine in the designated order. What could be causing my code to not function as expected?

Currently, I am working on developing a Simon game. In order to make the divs glow in the sequence of the array used, I have implemented the glowInOrder() function. However, I am facing an issue where only the first div in the array glows, while the rest d ...

How can I show the text name as a selection in the React Material UI Autocomplete component while sending the ID as the value?

Material UI Autocomplete component functions properly, but I am interested in extracting object.id as the value for the onSelect event (rather than object.name). Essentially, I want to display the object.name as the select item label, while retrieving obje ...

Utilize the "use" tag as a fallback to png files

Having some trouble with displaying SVGs on older versions of IE. My main question is: Is there a way to switch to a png as a fallback while using the "use" tag? I'm currently working with Angular 2, so if there's a solution within this framewor ...

Leveraging *ngFor to iterate through data retrieved from the server

I am completely new to Angular. Currently, I am retrieving the list of posts from the server using the code snippet below: loadPosts():boolean{ if (!LoginService.authenticated){ console.log('not auth'); return false; } // fetching posts. co ...

Exploring Angular 5's *ngFor directive with an array of objects

Here is the data I am working with: Initial set of data: var input = [ {ru: "R201", area: "211", unit: "211"}, {ru: "R201", area: "212", unit: "NONE"}, {ru: "R201", area: "HCC", unit: "NONE"}]; Desired result data: var result = [ {area: ...