Code Snippets

Allow HTML inputted from your AJAX into your HTML in the new version 5+ | angular

Say our var from JS / AJAX is called kit.difficultyTRANS

We pass it to the .html from the .ts, e.g. : TYPESCRIPT, NOT PHP: kit.difficultyTRANS = 'CORRECT You win';

We now want to show it. But every HTML tag has been converted with the equivalent of htmlspecialchars or whatever.

// // SO:
// // instead of: 

<span>{{kit.difficultyTRANS}}></span>  // // will output html special characters - not good - your output wil be "<b>CORRECT</b> You win"

 * Let's use:

<span [innerHtml]="kit.difficultyTRANS | safeHtml"></span>  // // it works, as long as we have made a pipe called safeHtml - your output will be as you wished for, with the html in tact

// // now, we have the Pipe setup in the TS files, like main.ts, app.component.ts, etc.  Depending on how you have structured it.  The pipe in this case is called "safeHTML".  (the camel case gets me everytime with this one).  
// // You CANNOT use the below - it will not work.  A little annoying if you are used to template engines.

<span>{{kit.difficultyTRANS | safeHtml}}></span> // // this will NOT work - infact it won't even NG SERVE or NG BUILD.  Thankfully their CLI has incredible debugging

Published: Fri 26th January 2018
||COMMENTS|| This site proudly uses PrismJS to display code snippets

If you like this page, please share it.

Code Links - PHP, JS, CSS, Bootstrap, Bash, Emmet, IntelliJ, Sublime etc.

My personal list of links which I keep here publicly incase they help someone else one day.

Code Snippets

Snippets of PHP code I have gathered over the years. I keep them here for my own repository but also to share with others. I always link back when I remember the source.

My Github Repos

A work in progress. I am going to make as many modules that I write in my devbox public as possible.

Kit's Homepage

This site was originally intended as a test bed for code. It now includes my blog about business and powerlifting, as well as games for Spanish language learning

© 2018