AngularJS requires that JSON object property values be converted to strings in order to be displayed as actual templates

Each tab click accesses a json array containing unique templates such as ui-grid or c3 chart directive (c3.js).

When a specific tab is clicked, the template in string format must be rendered into actual templates like ui-grid, c3-chart, etc.

var sampleJsonArray = [{
        id: 0,
        tabName: "Table",
        template: '   <div id="queryListGrid" ui-grid="queryListGridOptions" class="grid query-list-grid"></div>'
    },
    {
        id: 1,
        tabName: "Cost - Line",
        template: ' <c3-simple id="view1" config="c3ChartCost"></c3-simple> '
    },
    {
        id: 2,
        tabName: "Spend - Bar",
        template: ' <c3-simple id="view2" config="c3ChartSpend"></c3-simple> '
    },
];

Each tab has its own template stored in JSON format:

$scope.queryListGridOptions = {
    enableSorting: true,
    columnDefs: [{
            field: 'name'
        },
        {
            field: 'gender'
        },
        {
            field: 'company',
            enableSorting: false
        }
    ],
    data: //data will be fetched from http call -- []
        onRegisterApi: function(gridApi) {
            $scope.grid1Api = gridApi;
        }
};

$scope.c3ChartCost = {
    size: {
        height: 250,
        width: 200
    },
    data: {
        columns: [
            ['data1', 30, 200, 100, 400, 150, 250],
            ['data2', 130, 100, 140, 200, 150, 50]
        ],
        type: 'line'
    }
};
$scope.c3ChartSpend = {
    size: {
        height: 250,
        width: 200
    },
    data: {
        columns: [
            ['data1', 5, 510, 160, 700, 190, 960],
            ['data2', 87, 450, 56, 780, 670, 890]
        ],
        type: 'bar'
    }
};

Answer №1

To handle this issue, you may need to utilize the `$sce` service offered by Angular. Strict Contextual Escaping (SCE) is a feature that requires AngularJS to ensure certain bindings produce values that are safe for their intended use. Unfortunately, I don't currently have the time to provide you with a functional code snippet. You can refer to this documentation directly from Angular for more information. Feel free to reach out if you require assistance in the future.

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

Various JSON Tag values occurring more than once

Upon receiving a JSON Object in HTML, I am passing it to a JavaScript function defined below. The issue arises when the same folderName appears repeatedly on the HTML page. JSON Object: { "folderName": "arjunram-test", "objects": [ { ...

Error encountered on Windows 10 version 10.0.19044 during library installation with npm

I've encountered an error while trying to run or install libraries for a project within our organization. E:\GIT\bookshelf>npm install npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail= ...

Is it possible to create a single code that can be used for various buttons that perform the same function?

Whenever I click the right button, the left button appears and when I reach the last page, the right button disappears. However, this behavior is affecting both sections. Is there a way to write separate code for each section? I managed to make it work by ...

Obtain redirected JSON data locally using Angular 5

Currently, I am working on retrieving JSON data which will be sent to my localhost through a POST method. The SpringBoot API controller will validate the JSON content before forwarding it to my localhost. My task is to intercept this JSON data when it is t ...

Getting input elements with Puppeteer can be done by waiting for the page to fully load all elements within the frameset tag

Seeking to gather all input elements on this website: This is how the element source page appears. Below is my code snippet: const puppeteer = require("puppeteer"); function run() { return new Promise(async (resolve, reject) => { try { ...

Interactive tooltip with hyperlinks powered by jQuery

Is it possible to create a pop-up window with links that behave like a normal tooltip but can be clicked on by the mouse? How can this functionality be achieved without losing focus when hovering over the links causing the window to close? jQuery(docume ...

Is there a way to transform a string into a human-readable slug?

Is there a way to convert a slugified string into a more human-readable format? I am extracting parameters from a URL: bookmark/10/disco%20asdasd From this, I have the name "disco%20asdasd". However, this is not easily readable so I need to change it to ...

Can you explain the contrast between the functions 'remove' and 'removeChild' in JavaScript?

I have recently coded an HTML page in order to gain a better understanding of how element removal functions. Code: <html> <head> <script> var childDiv = null; var parent1 = null; var parent2 = null; function ...

Implementing popup alert for multiple tabs when Javascript session times out

I have implemented javascript setInterval() to monitor user idle time and display a popup alert prior to automatic logout. However, it seems to be functioning correctly only in single tabs. Here is the code snippet: localStorage.removeItem("idleTimeValue ...

Issue encountered while attempting to load bootstrap in NodeJS

I encountered an error while running my jasmine test case in node. The error message says that TypeError: $(...).modal is not a function. This error pertains to a modal dialog, which is essentially a bootstrap component. To address this issue, I attempted ...

jQuery failing to transmit JSON in AJAX POST call

I'm a bit perplexed at the moment, as I'm attempting to send data to my Node.js server using the code snippet below: $.ajax({type:'POST', url:'/map', data:'type=line&geometry='+str, succe ...

Crafting 3 intertwined combinations using the power of jQuery AJAX and PHP

Here's what I've been working on so far: The first page retrieves data and populates the first combobox, which is all good. Then, when users select a value from combo1, a second combobox is created with filtered data using AJAX - also working fin ...

Replace the value of a variable when another variable becomes false in Angular.js

Currently, I am working on a project using Angular and have run into an issue that I need help with: In my project, I have two variables - signed which is a boolean bound to a checkbox, and grade which is an integer bound to a number input field. I am lo ...

Image not showing up when using drawImage() from canvas rendering context 2D

Need help with drawImage() method in JavaScript <head> </head> <body> <script type = "text/javascript"> var body, canvas, img, cxt; body = document.getElementsByTagName("body" ...

What is the best way to identify key presses using Javascript?

Exploring various resources online, I have come across multiple recommendations (such as using window.onkeypress or jQuery) but each option comes with its own set of criticisms. How can the detection of a keypress be achieved in Javascript? ...

The json_encode function in Javascript is not returning a valid value

I am facing an issue with a PHP array that I encode using json_encode and then pass to a variable in a JavaScript function. Even though the array seems fine after encoding, it appears as a valid JavaScript array. However, I keep receiving 'undefined&a ...

changing the validation function from using if statements to utilizing switch statements

Currently, I am refactoring a form in react and planning to offload most of the state and logic to the parent component. This decision is made because the parent's state will be updated based on the form submission results. However, I encountered an i ...

Examine each of the elements in the ng-repeat loop

When it comes to the first prematchGame having a value of 1 and 2, I encounter an issue where the first element does not have these values, but the 3rd and 4th elements do. (refer to the image) Is there a way for me to check if the 1st element in ng-repea ...

gulp.watch executes tasks without following a specific sequence

Objective Develop a gulp.watch task to execute other tasks in a specific sequence Why this is unique While many have referred me to How to run Gulp tasks sequentially one after the other, my query differs as it pertains to using gulp.watch instead of gu ...

Using JQuery within Angular 4 is a valuable tool for enhancing the functionality

As a newcomer to Angular, I am experimenting with using jQuery alongside Angular 4. In my search for information, I stumbled upon this question on Stack Overflow. Inside the question, there was an example provided that can be found here. However, when att ...