Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8054841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:14:19+00:00 2026-06-05T08:14:19+00:00

Is it possible to create an HTML fragment in an AngularJS controller and have

  • 0

Is it possible to create an HTML fragment in an AngularJS controller and have this HTML shown in the view?

This comes from a requirement to turn an inconsistent JSON blob into a nested list of id: value pairs. Therefore the HTML is created in the controller and I am now looking to display it.

I have created a model property, but cannot render this in the view without it just printing the HTML.


Update

It appears that the problem arises from angular rendering the created HTML as a string within quotes. Will attempt to find a way around this.

Example controller :

var SomeController = function () {

    this.customHtml = '<ul><li>render me please</li></ul>';
}

Example view :

<div ng:bind="customHtml"></div>

Gives :

<div>
    "<ul><li>render me please</li></ul>"
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:14:20+00:00Added an answer on June 5, 2026 at 8:14 am

    For Angular 1.x, use ng-bind-html in the HTML:

    <div ng-bind-html="thisCanBeusedInsideNgBindHtml"></div>
    

    At this point you would get a attempting to use an unsafe value in a safe context error so you need to either use ngSanitize or $sce to resolve that.

    $sce

    Use $sce.trustAsHtml() in the controller to convert the html string.

     $scope.thisCanBeusedInsideNgBindHtml = $sce.trustAsHtml(someHtmlVar);
    

    ngSanitize

    There are 2 steps:

    1. include the angular-sanitize.min.js resource, i.e.:

      <script src="lib/angular/angular-sanitize.min.js"></script>
      
    2. In a js file (controller or usually app.js), include ngSanitize, i.e.:

      angular.module('myApp', ['myApp.filters', 'myApp.services', 
          'myApp.directives', 'ngSanitize'])
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to create a popup from a contextmenu? Like this: http://code.google.com/chrome/extensions/getstarted.html But,
Is it possible to create a html file that can be loaded from jQuery
Is it possible to create a custom border for an html table from an
Is it possible to create a Partial View, which has a controller, which can
Is it possible to create HTML output from the contents of an HTML snippet
Is it possible to create this image by CSS/HTML only, without JavaScript? Because the
Is it possible to create the curved sail shape below using HTML and CSS
Is it possible in javaScript to create an html file in same directory ?
Possible Duplicate: Mvc Html.ActionButton With ASP.NET MVC 3 I know how to create a
Is possible create facebook app with 100% width? Something like this: https://apps.facebook.com/what_car_fits/ (app has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.