AngularJS Issue: Duplicate Error

Attempting to refresh data after making some changes results in duplicate errors appearing within the ng-repeat.

The scenario is as follows;

I am working on creating a dynamic menu module

The requirements include adding, deleting, changing the order, and assigning items to different Mainmenu items etc.

Everything is functioning properly except for reloading the menu structure in a table format.

After clearing the original Object, the table becomes empty showing no data. When attempting to reload the altered data, duplicate errors occur. The only solution seems to be reloading the browser to display the correct information until the next update.

The challenge lies in not being able to push and splice the array due to potential issues with indentation and the possibility of changing the order.

The code

The module

"use strict";
// no dependencies
angular.module('appWebmenu', []);

The Main Directive

'use strict';

angular.module('appWebmenu').directive('appWebmenu',function() {
    return {
        scope:false,
        controller: 'appWebmenuController',
        templateUrl: 'external/appWebmenu/appWebmenuTemplate.html'
    };
});

The List Directive The actual table The scope is Moved to the Module Controller

angular.module('appWebmenu').directive('appWebmenuList', function() {
    return {
        transclude: true,
        templateUrl: 'external/appWebmenu/appWebmenuListTemplate.html',
        controller: 'appWebmenuController',
        scope: false
    }
});

The Template

<div ng-if="!listLoaded">
    <i class="fa fa-spinner fa-spin fa-3x"></i>
</div>

<div ng-if="listError">
    {{ 'ERROR_LOADING' | translate }}
</div>

... (template continues)

And Finally the Controller

angular.module('appWebmenu').controller('appWebmenuController', ['$scope', 'dataService', 'webmenuService', 'loadService', function ($scope, dataService, webmenuService, loadService) {

    $scope.title = "Site menu pages"
    // Different settings to control view and loading
    ...

    ... (controller continues)

The JSON being loaded

{
    0: {
        ...
    },
    1: {
        ...
    },
    ...
}

Tried implementing solutions such as using track by $index or a unique identifier like menu_id, but it does not solve the issue and may even worsen it.

If anyone has any insights or solutions, I would greatly appreciate the help.

Answer №1

After investigating, I identified the issue. The mistake occurred when the PHP code produced duplicate output, resulting in repeated JSON objects. It was a rookie error on my part for forgetting to clear a certain variable.

It's interesting how an internal class variable in PHP can persist between separate requests, even though it seems strange at first glance.

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

Dealing with a passed EJS variable in string form

When working with passed data in ejs, I usually handle it like this and it works perfectly: let parsed_json = JSON.parse('<%-JSON.stringify(passed_data)%>'); However, I encountered a problem when trying to dynamically pass a string variabl ...

What is the best way to collapse a button in asp.net using javascript after setting it to hidden?

I have a scenario where I have 3 buttons in a row on my asp.net page. Using JavaScript, I am setting the middle button (ButtonSR) to invisible. However, I want the button below it to move up and take its place instead of leaving an empty space. ...

Verify the MAC address as the user types

I need to verify a form field for MAC Addresses and have implemented the following code that does the job. $('body').on('keyup', '#macAddess', function(e){ var e = $(this).val(); var r = /([a-f0-9]{2})([a-f0-9]{2})/i, ...

Unlocking the power of NextAuth by incorporating wild card or custom domains into the signin logic

My NextJS application is a multi-tenant SaaS application where each customer can choose to use a subdomain on our site or map their custom domain via CNAME. This setup allows customers to enable their employees to log in on either the subdomain site or cu ...

Jquery unresponsive in AJAX form output presentation

I recently delved into the world of jquery and AJAX, and while I grasp most concepts, I'm struggling with a small code snippet. On my webpage, there is a summary of articles. Clicking on an article name triggers a popup window with detailed informati ...

What could be causing the entire app to malfunction when the Redux Provider tag is used

I am facing an issue while trying to integrate a React Toolkit app into my project. The error message I encountered is as follows: Error: Invalid hook call. Hooks can only be called inside the body of a function component. This error may occur due to one ...

Tips on waiting for an event to be processed during a Protractor end-to-end test

I have a straightforward AngularJs 1.4.8 Front-End: https://i.stack.imgur.com/2H3In.png After filling out the form and clicking the OK button, a new person is added to the table. The form resides in the addingPersonController, while the table is control ...

Ways to permit https://* within a content security policy (CSP) configuration

I'm currently incorporating CSP into my website but encountering an issue with the img-src header. I'm using NodeJS and Express to develop the site for my Discord Bot, and I want to revamp it but I've hit a roadblock. ====== This is the co ...

Ways to retrieve the state within a mapping array

I am currently facing an issue that I need assistance with: this.state.renderMap.map(function(name, index) { return ( <View style={styles.checkBoxWrapper} key={index}> <CheckBox title={name} value={() => {this.state.nam ...

JavaScript with dropdown menus

Currently, I am in the process of implementing a JavaScript code snippet that will be triggered when a checkbox is checked. Once the checkbox is checked, the form should display two additional select boxes. My attempt at coding this functionality was not ...

Creating dependent dropdowns using Laravel Inertia Vue: A step-by-step guide

In my AddressController, I have a function called loadCity along with other CRUD functions: public function loadCities(Request $request) { $provinceId = $request->province_id; $cities = Province::where('province_id' ...

Retrieving information from an Express.js API using React.js. Postman requests are successfully communicating with the API

Hey there, I'm facing a little issue and could use some help. I have an Express application that is working perfectly with requests from Postman (adding, deleting, etc.). Now, I want to connect my client side (React.js) with the existing API using the ...

The combination of React.js and debouncing on the onChange event seems to be malfunctioning

I recently incorporated a React component that triggers an event on change. Here's how I did it: NewItem = React.createClass({ componentWillMount: function() { this._searchBoxHandler = debounce(this._searchBoxHandler, 500); }, _searchBoxH ...

What impact does changing the Device Language have on a heading?

At the top of an html page, I have the word "Color" in a heading. If a user's device is set to British English, I would like the text to automatically switch to "Colour". What is the best way to accomplish this with minimal Javascript? ...

Is there a more efficient method for iterating through this object?

Working with JSON and JS var data = { "countries": { "europe" : [{name: "England", abbr: "en"}, {name: "Spain", abbr: "es"}], "americas" : [{name: "United States"}], "asia" : [{name: "China"}] } }; JavaScript Loop for (k in data) { fo ...

How to redirect to a different view or controller using ASP.NET and AngularJS

How can I open the View located at /Home/CreateItem after clicking on the Add button? What do I need to include in my code? $scope.Add = function() { console.log('working'); } This is how Index.cshtml looks like: <script src="~/ ...

Tips for preventing text from changing its padding within a div when reducing the width and height dimensions

I am facing an issue with a div inside another div. The child div contains text, and when I apply animation to decrease the width and height, the text inside gets reset according to the new size. While I understand why this happens, I want to find a way to ...

Trouble arises when attempting to use JavaScript, JSP, and JSON in conjunction with

I am in the process of creating a client-server application where I send a request from the client to the server using a JSON object for registration. However, despite receiving a JSON response with an "OK" field as expected, the client keeps triggering th ...

Adding the unzip feature is not within my capabilities

I am a novice Japanese web developer. Unfortunately, my English skills are not great. I apologize for any inconvenience. I am interested in utilizing this specific module: https://www.npmjs.com/package/unzip To do so, I executed the following commands ...

Unable to execute a JavaScript function when triggered from an HTML form

This is the code for a text conversion tool in HTML: <html> <head> <title> Text Conversion Tool </title> <script type="text/javascript"> function testResults(form) { var str = form.stringn.value; var strArray = str.split(" ...