Angularjs Error Message: Syntax Parsing Issue

Being new to AngularJS, I am trying to grasp the error messages displayed in the console. Below are my JSON object and other details for reference.

In the JSP page:

<body id="bodyID" ng-controller="ApplicationParameterController" >
    <div ng-cloak class="ng-cloak">{{init(${displayInfo})}}</div>
    <toaster-container toaster-options="{'time-out': 3000}"></toaster-container>
    <application-param></application-param>
</body>

My JSON object:

displayInfo = [{"id":34,"key":"a","value":"true","description":"a","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":35,"key":"summaryReportEmail","value":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="582c3d2b2c183f35393134763b37353148743b3e">[email protected]</a>","description":"summaryReportEmail","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":36,"key":"b","value":"true","description":"b","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":1,"key":"T_AND_C_ON","value":"Y","description":"c","privilege":{"privilegeID":74,"privilegeCode":"enable_tnc"}},{"id":3,"key":"soapAddress","value":"http://test.com/test/test.asmx","description":"soapAddress","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":4,"key":"soapAddressAlter","value":"http://test.com/test/test.asmx","description":"soapAddressAlter","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":27,"key":"d","value":"d","description":"d ","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":28,"key":"sts.s3.bucket.name","value":"test01-sts-healix-xmls","description":"sts.s3.bucket.name","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":29,"key":"e","value":"e","description":"e","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":30,"key":"f","value":"f/g","description":"f","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":31,"key":"g","value":"7","description":"g","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":32,"key":"enableScheduler","value":"true","description":"enableScheduler","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}},{"id":33,"key":"sts.document.api","value":"http://www.test.com/as-da-api","description":"sts.document.api","privilege":{"privilegeID":77,"privilegeCode":"app_param_admin"}}]

I am encountering the following error:

Error: [$parse:syntax] http://errors.angularjs.org/1.3.0-beta.14/$parse/syntax?p0=undefined&p1=is%20unexpected%2C%20expecting%20%5B%7D%5D&p2=null&p3=init(%5B%7...G/<@https://localhost:8443/travelinsurance-aggregator/resources/scripts/angular.min.js:6:457

The init method I am using is:

$scope.init = function(displayInfo) {
                if ($scope.displayInformation == null || $scope.displayInformation == 'undefined') {
                    $scope.displayInformation = angular.fromJson(displayInfo);
                    $scope.applicationParameters = $scope.displayInformation;
                }
            };

Despite no syntax errors being detected by json formatter, an error message stating otherwise is persisting. After researching various sites, I was unable to find a solution for this error.

If anyone can offer guidance on resolving this issue, it would be greatly appreciated. Thank you in advance.

Answer №1

The root of the problem has been identified. When attempting to convert an object of object into a JSON string, this code was initially used:

ObjectMapper jsonMapper = new ObjectMapper();
String displayJson = null;
try {
    displayJson = jsonMapper.writeValueAsString(applicationParametersForPrivilege);
} catch (Exception e) {
    e.printStackTrace();
}

However, after consulting this source, the approach was modified to:

ObjectWriter jsonMapper = new ObjectMapper().writer().withDefaultPrettyPrinter();
String displayJson = null;
try {
    displayJson = jsonMapper.writeValueAsString(applicationParametersForPrivilege);
} catch (Exception e) {
    e.printStackTrace();
}

This adjustment resolved the issue and the functionality is now operating as expected.

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

Preventing duplicate entries from being stored in the database when importing data from an external JSON file using Sidekiq in a Rails application

My current challenge involves managing a small To Do list stored in a .json file. I have set up a system where I read, parse, and save this list to a Rails app using Sidekiq. However, every time I refresh the browser, the worker runs again and duplicates t ...

Using jQuery's ajax function to send data with a variable name of data field

I am trying to figure out how to dynamically add a variable to the name of the data field I want to send information to through ajax. Below is an example of the code I'm working on: var qty = $('#qty_'+value).val(); $.ajax({ url: &apo ...

Issue with the successful execution of connection event handler in NodeJS and Socket.io?

When I look at my code in files named server.js and index.html, I notice that the io.on('connection') part is not executing the console.log method in its callback when I visit my server in the web browser. Take a look at the code snippets below ...

Read through the text, determine the length of each word, and keep track of how

Objective: Create a JavaScript program that takes input from users in the form of several lines of text and generates a table displaying the count of one-letter words, two-letter words, three-letter words, etc. present in the text. Below is an example ou ...

Tips for refreshing the <img> tag using a user image

I am currently designing a bootstrap webpage and trying to implement a feature where the user can input an image, which will then be displayed in a preview modal along with some text provided by the user. The modal is functioning correctly. Here is the co ...

Inject a DOM event into a personalized form validator within an Angular application

I'm currently working on validating a form using the reactive approach. I've implemented a file input to allow users to upload files, with custom validation conditions in place. However, I'm encountering an issue where the validator only rec ...

How can one ensure that Discord waits for a script to complete running, and how can you prevent Discord from responding until all necessary data has been obtained?

I recently started working with node.js and asynchronous programming, and I'm facing a challenge that has me puzzled. My goal is to create a Discord bot that fetches data from a third-party website. While I can successfully retrieve the data and see i ...

What could be causing my Mocha reporter to duplicate test reports?

I've created a custom reporter called doc-output.js based on the doc reporter. /** * Module dependencies. */ var Base = require('./base') , utils = require('../utils'); /** * Expose `Doc`. */ exports = module.exports = ...

The method of reading a unique array of objects for each radio button

Currently, I am facing an issue when trying to retrieve unique elements for each radio button from the database. The data structure and information obtained from the database are as follows: { FormularID: 182, CampaignID: 14, FormLabel: & ...

Utilizing Javascript to initiate an AJAX call to the server

I am creating an application similar to JSbin / JS fiddle. My goal is to update my database by making an ajax request to the server when the user clicks on the save code button and submits the values entered in the textarea. However, I seem to be encount ...

Input specific ng-if conditions

I'm a bit confused about the conditions for my ng-if and could use some assistance. I have a form on my page that is rendered using ng-repeat and a couple of custom filters. You can check out this plunker. The issue I'm facing is that I need to p ...

Is there a way to implement the post method in ng2-smart-table whenever a new row is inserted?

Incorporating the ng2 smart table library into my angular 2 project has been helpful. I am now faced with a requirement to trigger an API request using the http.post() method whenever a new row is added to the table. Is there a way for me to retrieve the ...

What is the method for obtaining a unique exception message in the ajaxError event of jQuery?

Is there a way to customize the content of responseText in my APP? Currently, it displays as exception description amended by Tomcat (refer to the image below). I want to have control over the content of responseText or handle custom messages in a more eff ...

Leveraging dependency injection in Angular 2+ with pre-loaded models

I desire the ability to create an instance of a model using a constructor while also providing injected services to that model. To clarify, I envision something like this: var book = new Book({ id: 5 }); // creates instance, sets id = 5 book.makeHttpCa ...

A user-friendly JavaScript framework focused on manipulating the DOM using a module approach and aiming to mirror the ease of use found in jQuery

This is simply a training exercise. I have created a script for solving this using the resource (function(window) { function smp(selector) { return new smpObj(selector); } function smpObj(selector) { this.length = 0; i ...

Combining shared table rows with embedded ruby code in Javascript - is it possible?

I'm a new Javascript learner and I'm attempting to create a function that will merge rows with the same value (year in this case) and add their numbers together. Although my code isn't functioning as expected, it also doesn't seem to be ...

Having trouble getting your jQuery code to work in your HTML document after converting it to

Recently, I've been working with HTML5, CSS, and vanilla JavaScript. I wanted to convert this jQuery code and make some changes to it. However, I seem to be encountering an issue after implementing the new code. The original code had a small triangu ...

Refreshing the page is the only way to activate the jQuery function

I am currently using the $.getJSON(...) method to fetch JSON data (images) for my HTML web page. The getJSON() function is triggered once the DOM has fully loaded: $(document).ready(function() { Subsequently, I am utilizing the montage.js library to orga ...

Switching the positions of the date and month in VueJS Datepicker

Recently, I have been utilizing the datepicker component from vuejs-datepicker. However, I encountered an issue where upon form submission, the date and month switch places. For instance, 10/08/2018 (dd/MM/yyyy) eventually displays as 08/10/2018, leading ...

How can I assign a reference to a List component using react-virtualized?

Could someone help me with referencing the scrollable List in react-virtualized using a ref? I'm having trouble as my ref keeps showing its current attribute as undefined. Any tips on how to properly use a ref with react-virtualized List? This is wha ...