Attention: certain content may have been removed due to HTML sanitation

Hi there, I'm currently working on incorporating a search bar into a modal window by embedding HTML within the modal body. Here's how I've written the code:

onClick() {
      const dialogRef = this.modal.alert()
        .size('lg')
        .showClose(true)
        .title('A simple Alert style modal window')
        .body(`
          <div class="card container-fluid col-xs-10">
          <div class="card-block">
              <div class="form-group row">
                  <div class="col-5">
                      <ng2-completer class="completer-limit"
                                     [(ngModel)]="searchStr"
                                     [datasource]="dataService"
                                     [minSearchLength]="0"
                                     [inputClass]="'form-control'"
                                     [placeholder]="'Enter the class you would like to add'"
                                     [matchClass]="'match'"
                                     [autofocus]="true"
                                     [textSearching]="false">
                      </ng2-completer>
                  </div>
              </div>
          </div>
      </div>`)
        .open();
    }

The issue arises when trying to reference data in the same TypeScript file as the onClick function within the HTML embedded in the modal's body. Running this HTML separately works perfectly (without being in a modal), and inserting generic HTML content within the modal also functions correctly. However, upon including the above code snippet, the search bar fails to render, and the developer console displays a warning stating that some content was stripped due to HTML sanitization. Does anyone have any insights into what could be causing this? It's possible that the problem lies in the inability of the HTML within the modal body to access objects in the TypeScript file where the onClick function resides. Could it be related to the fact that the template is referencing a separate HTML file, or should it still be able to access objects from the TypeScript file?

Answer №1

One issue lies in sending HTML within a string to the modal.alert().body() method

Due to security concerns, Angular does not trust this input and sanitizes it to prevent potential code injection. To work around this limitation, consider using a template or component as an alternative approach if your modal supports it.

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

Utilizing a Node.js web server in conjunction with an Apache Cordova Application

I have created an innovative Apache Cordova Application that leverages a Node.js web server to retrieve data from a web API, enabling the JavaScript-based project to utilize the information obtained from the API. Is there a method to integrate this Node w ...

I'm struggling to figure out how to specify the data type for storing an array of objects in a variable using React.useState

I am currently working on extracting values from an .xlsx file using the SheetJS library. Below, I will provide the code snippets, errors encountered, and the different approaches I have attempted. Data extracted from var dataToJson: (6) [{…}, {…}, { ...

Client-side filtering for numerical columns using the Kendo UI Grid widget

In my Kendo UI grid widget, I have a model schema set up for a field like this: RS_LookBackDays: { type: "number", editable: true }, The columns configuration for the same field looks like this: { field: "RS_LookBackDays", title: "Rate Schedule – # Lo ...

Is there a way to have text appear in a popup when I reach it while scrolling?

Is there a way to make the textblocks on my website increase in size or pop up when I scroll down to them? I've attempted to search for a solution online but have been unsuccessful in finding one. ...

Feeling lost with the concept of getcontext in js/ts and uncertain about how to navigate through it

Recently, I've been encountering undefined errors in my browser and can't seem to figure out how to resolve them. It seems that the usage of the keyword "this" in JavaScript and even TypeScript is causing quite a bit of confusion for me. Let&apo ...

transformed an Angular 2 web application into a sleek and functional mobile application

I am looking to convert my basic angular2 web application into a mobile app using cordova. Is there a way to achieve this without relying on Ionic or nativeScript? ...

Enable Sound when Hovering over Video in React Next.js

I am currently facing an issue while trying to incorporate a short video within my nextjs page using the HTML tag. The video starts off muted and I want it to play sound when hovered over. Despite my best efforts, I can't seem to get it working prope ...

Avoiding repetitive rendering of child components in ReactJS

In my React project, I have a parent component that contains 3 children components, structured like this: var Parent = React.createClass({ render: function() { return (<div> <C1/> <C2/> <C3/> ...

Skip creating declarations for certain files

src/ user.ts department.ts In the scenario outlined above, where there are two files in the src directory (user.ts and department.ts), is there a way to exclude the generation of declaration files specifically for department.ts when running tsc wi ...

Why does TypeScript struggle to accurately deduce the return type when provided with certain parameter values?

I have a function that uses a switch case to return different results depending on the input. The function, called "getTimeAgo," takes in two parameters: "date" (which can be either a Date object or a string) and "mode" (which can only be either "days" or ...

How do I access the content of a webpage once it has been generated using a template engine?

Currently, I am engaging in screen scraping for a website that heavily relies on JavaScript. The site utilizes a client-side templating engine to display all of its content. Initially, I attempted to use jQuery, which proved successful in the console but n ...

Encountering the error message "This expression cannot be invoked" within a Typescript React Application

I'm working on separating the logic from the layout component in my Typescript React Application, but I suspect there's an issue with the return type of my controller function. I attempted to define a type to specify the return type, but TypeScr ...

Is it possible to modify the labels on CKEditor's toolbar elements?

Initializing CKEditor in the following manner: function init() { $( ".ckeditor" ).ckeditor( { format_tags: 'h3;p', toolbar: [ [ "Source", "-", "Bold", "Italic" ], [ "Link", "Unlink" ], [ "Blockquote", "F ...

Node.js Monitoring Statistics Displayed in Command Line Interface

Apologies if this question has been asked before. I have been looking for something similar to what I need, but haven't been able to find it anywhere. So, I thought I'd ask. I am working with a nodejs script using puppeteer and I want to view st ...

Using *ngFor alters the positioning of components

After implementing a flexbox container class to align my components horizontally, I noticed that when using input properties and a loop, they are displayed stacked vertically instead. <div class="flexbox-container" > <app-card></ ...

Can Angular Routing support distinct 'path' strings for various languages?

I've been working on an internationalized Angular app, and it's performing really well so far. However, I've noticed that I have the same route strings for different languages, which could negatively impact SEO. Is there a way to make the ...

Retrieve the template parameter from a generic type

While I have experience extracting string from string[], this particular scenario is proving to be quite challenging: type example<T = boolean> = true; // with just "example", how can I retrieve the template parameter "boolean" in this case? type T ...

Deactivating Chrome Autofill once more in version 70.0.3538.67

Unfortunately, with the latest Chrome version 70.0.3538.67, all my previous methods of disabling autofill/autosuggest no longer seem to be effective. I am looking for a clean solution that is practical and efficient. Additionally, I have forms with a com ...

Creating a new session in Node.js for every request

Our team is currently developing a nodejs application that requires the maintenance of sessions. We have implemented express to handle node variables, but we are facing an issue where a new session is created every time we hit a new service. The structure ...

Using TypeORM in Javascript to create routes efficiently

After examining the TypeORM websites examples, I noticed that some of them demonstrate routing usage using TypeScript. Given that TypeORM has the capability to use JavaScript instead of TypeScript, I am seeking guidance on how to implement Express routing ...