Using AngularJS, you can format JSON attributes by storing them as scope variables

I am attempting to display JSON data in a view using the json-formatter plugin.

Within the controller, I'm utilizing a service to make a REST API call for a schema. Once the request is complete, the result is stored in a scope variable. Here's a snippet of the code:

.controller('SchemaCtrl', ['$scope', '$routeParams', 'Schema','$log', function($scope, $routeParams, Schema,$log){
    Schema.show($routeParams.name).then(function(schema){
        $scope.schema = schema;
        $scope.schemaShow = true;
    });

In the view, my code looks like this:

{{schema}}
<div>
    <json-formatter open="1" json="{{schema}}"></json-formatter>
</div>

Unfortunately, when running the example, I encounter the following error:

Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{schema}}] starting at [{schema}}].
{{schema}}

I understand that the issue stems from the way the json-formatter directive processes data before Angular replaces {{schema}} with the correct value. How can I properly pass values through scope variables while using the json-formatter plugin?

By the way, Using hardcoded JSON works without any issues.

Answer №1

JSON provides bi-directional binding in json-formatter, removing the need for interpolation symbols like {{}}.

<div>
    <json-formatter open="1" json="schema"></json-formatter>
</div>

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 React with file system and path dependent packages

Is there a way to utilize the quick.db package in my ReactAPP with hooks, even though React does not allow the use of FS & Path which are required for this package? I am encountering the following errors: ERROR in ./node_modules/file-uri-to-path/index.js ...

Attempting to resolve the Bootstrap issue, currently in search of a suitable solution

Today I made the decision to utilize bootstrap to create a menu, but unfortunately, I've encountered a strange bug or conflict involving jQuery, potentially the UI, and Bootstrap. If you'd like, you can take a look at the picture provided in the ...

A guide on implementing a jQuery click function on ng-click in an AngularJS application

Currently, I am developing a mobile app and utilizing MDL for the app's UI along with Angular JS. The theme I purchased from ThemeForest is called "FAB." My goal is to display data from the server using API's and showcase all the products that ar ...

Restricting slash commands in Discord.js to a specific permission level

I'm currently developing a purge command, and I'm struggling to restrict its usage to users with the MANAGE_MESSAGES permission. Below is the source code for the client.on("ready") section as well as the entire command logic. Any assistance on ...

Challenges integrating Jquery with Flask

When attempting to add an HTML element using jQuery, I encountered an exception from Flask: jinja2.exceptions.TemplateSyntaxError: expected token ',', got 'static' The string seems correct, but I'm unsure about what the issue ...

How can you prevent multiple instances of JavaScript objects from being disposed of after they have completed their task?

I'm facing an issue with the code snippet below: $(document).ready(function() { $('.container').ready(function() { var v = new Video($(this)); v.load(); }); }); I'm trying to prevent the object 'v&apos ...

Why does the final value appear when passing an incrementing counter as a prop to multiple React Components created in a loop?

I am currently unraveling the concept of closures in JavaScript. Within this code snippet, I am cycling through the values of the 'items' array using a foreach loop. I have defined a let variable named "count" outside the scope of the loop. Afte ...

Initialize spinner with data stored in SharedPreferences

I have a JSON array saved in shared preferences and retrieved it as a string: SharedPreferences prefs = getContext().getSharedPreferences("preferences", Context.MODE_PRIVATE); prefs.getString("classes", classes); My goal now is to populate a spin ...

Tips for converting JSON into a usable array for a foreach loop

I am currently working with the following text ($results): {"data":{"summary":{"records":67,"page":1,"total":67,"hasMore":0},"reservations":[{"id":1111111,"property":"villadianna","from":"2016-07-18","to":"2016-07-25"},"pricing":{"price":1164.2400,"curren ...

d3: It appears that my routes are replicating themselves, and I am unable to ascertain the cause

I've been diving deep into D3, studying the works of Mike Bostock and other experts in the field. I'm also going through Scott Murray's book on Interactive Data Visualization specifically focusing on D3. At the moment, my project involves c ...

Incorporating library files (css/js) into your app built on the angular-fullstack framework

After using a Yo Angular-Fullstack generator (https://github.com/DaftMonk/generator-angular-fullstack) to start an app, I attempted to install Toastr from bower with the command: bower install angular-toastr Now, I need to add the toastr css and js files ...

Guide to incorporating a JSON file parsing method in Java

I am attempting to extract the data from a JSON file named text.json using the Jackson library. My goal is to create a Java method within the provided code that can retrieve all keys and values from the JSON file. However, my current implementation only f ...

Managed/Voluntary Input

Why is React showing an issue with controlled/uncontrolled input? The initial state of value is set to this.state.text, which starts as an empty string in the constructor. import React from 'react'; class MyComponent extends React.Component { ...

The Express.js middleware seems to be malfunctioning, as it is causing an excessive number of redirects

My Express JS middleware seems to be malfunctioning and displaying an excessive number of redirections. Even when I remove the token or log out, the browser indicates too many redirections. Middleware const isAuthenticate = async (req, res, next) => { ...

Incorporating a navigation bar into my Jade template

I am working with nodejs, express, and bootstrap for my project. While this may seem like a basic question, I have been unable to find the specific solution I need. My issue lies in the fact that I have a layout.jade file and an index.jade file, with the ...

What are some ways to improve performance in JavaScript?

Can you help me determine which approach would be more efficient - using native functions of the language that involve 2 iterations or a simple for loop? The goal is to locate the index in an array of objects where the property filterId matches a specific ...

Bug in Click Behavior of HTML5 Canvas on Webkit Browser Versions Below 535 for Android Native and iOS5 Safari

Recently, I encountered a peculiar bug in Android where positioning a canvas element on the Native Android Browser (WebKit 534.4) using css position:absolute; top:10px; left:100px; resulted in the duplicated Canvas being rendered to the browser while ignor ...

Tips for spinning each individual particle around its own axis within a Particle system in THREE.js?

I'm currently working on a space scene where I'm using a particle system to create a group of asteroids. I'd like to rotate each asteroid on its own axis. Below is the code snippet I'm using to set up the particle system: var asteroidG ...

The discrepancy between the ng-model value in the controller and the input field in the HTML

In my HTML code, I have an input field that is linked to a specific value using the ng-model attribute. Initially, any changes made to this ng-model in the controller are accurately reflected in the input field. However, when I manually type something into ...

The challenges with implementing makeStyles in React Material UI

const useStyles = makeStyles((theme) => ({ toolbarMargin: { ...theme.mixins.toolbar, marginBottom: "3em", }, logo: { height: "7em", }, tabContainer: { marginLeft: "auto", }, tab: { ...theme ...