The error in my filtering system

Creating a test filter that returns constant data was my goal.

mainApp.filter('dateParser', function () {
    return function (param) {
        return [{id:1,day:'23.07.17'},{id:2,day:'22.07.17'}];
    };
});

However, when I try to use it like this:

<td ng-repeat="crrDay in studentOne.daysList|dateParser">
        {{day.currentVal}}
</td>

I am able to retrieve the desired data but an error appears in the console:

Error: $rootScope:infdig
Infinite $digest Loop

Could you explain why this is happening?

UPDATE Full filter code:

mainApp.filter('dateParser', function () {
    console.log(this);
    return function (param) {

        var parse, sorted, result = [], parsedArray = [];

        for (var i = 0; i < param.length; i++) {
            parse = param[i].day.split('.');
            parsedArray[i] = {
                'id': param[i].id,
                'day': parse[0],
                'month': parse[1],
                'year': parse[2]
            };
        }
        sorted = _.sortBy(parsedArray, ['year', 'month', 'day']);
        for (i = 0; i < sorted.length; i++) {
            result[i] = {
                id:sorted[i].id,
                day: sorted[i].day + '.' + sorted[i].month + '.' + sorted[i].year
            };
        }
        return result;
    };
});

Answer №1

When you are returning a function within another function, make sure to update your filter in the following way:

mainApp.filter('dateParser', function () {
     return [{id:1,day:'23.07.17'},{id:2,day:'22.07.17'}];
});

function(param) is not necessary in this context.

UPDATE

If you need to include a parameter, use the following syntax:

mainApp.filter("dateParser", function() { 
   return function(input) { 
      //perform your actions and then return
  };
})

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

Differences Between Angular Routes and $resourceComparing Angular

In my application, I have a set of REST URLs that I need to fetch and display as HTML content upon user request. When the user searches for a first name and it is found, the HTML is populated from JSON data retrieved from the initial URL. Initial URL va ...

Customizing a thumbnail script to dynamically resize and display images according to their size properties

I am attempting to modify a simple JavaScript script that enlarges an image from a thumbnail whenever it is clicked. The issue I am facing is that the enlarged image is displayed based on a fixed width size. I want the enlarged image to be displayed accord ...

Utilizing SVG icons with AngularJS for optimal compatibility in Firefox

When integrating SVG icons with AngularJS and enabling html5Mode, it is essential to set the basePath in the html document's head. <base href="/"> To utilize SVG icons, all symbols need to be loaded into the index.html page like so: <?xml ...

Discovering a nested key within a JSON object in Vue.js - here's how to do it

Currently, I am attempting to showcase the list of users obtained from my Django API on my VUEjs application. Here is the data for the User list fetched from the API: { "count": 1, "next": null, "previous": null, &quo ...

analyzing properties through unit testing

Currently in the process of writing unit tests for computed properties. I have a file called fileOne.ts : export const fileOne = () => { const fx1 = computed ( () => { ... } ); const fx2 = computed ( () => { ... } ); const fx3 = comp ...

Tips for resolving the issue: "Encountered error loading module script..." in Angular 8 and Electron 5

I have been working on developing an Electron 5 app using Angular 8. Despite following numerous online tutorials, I keep encountering the same error. Initially, I set up a new project and ran ng serve --open, which successfully displayed the default angul ...

Obtain image measurements within directive during image uploading

One of my angular-js directives is used for 'uploading' local images. Here's the code: app.directive('ngFileModel', ['$parse', function ($parse) { return { restrict: 'A', link: function (sco ...

Issue with NodeJS: Unable to locate module 'io' (socket.io in combination with express version 4.15.3)

I am a beginner in NodeJS and I am attempting to create a simple chat application using the express and socket.io modules. However, when I try to run the application, I encounter an error on the page where I am utilizing the socket feature. The console dis ...

Manage form submission seamlessly without redirecting. Capture information without needing to prevent the default action, then proceed with redirection. Avoid redirecting when using preventDefault, but be aware that data may not

Currently stuck in a tricky situation. I've implemented a custom form submission to prevent redirecting when an express route is triggered by form submission. However, the issue arises when I lose the data being sent without redirection. document.get ...

The Objectid seems to be causing issues with the Mongodb find function

I've encountered an issue with my code where I am receiving a null value for the doc. Strangely, when I use findOne({'webpageid':docs[i]._id} and replace docs[i]._id with webpageid, it functions correctly. I have double-checked that docs con ...

Issue encountered while initializing an HtmlPage with HTMLUnit

When attempting to execute the following code: try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45)) { webClient.getOptions().setJavaScriptEnabled(true); final HtmlPage page = webClient.getPage("http://www.chem ...

Display the current position of the caret in a field that cannot be edited

Can a virtual caret be displayed between two letter boundaries in HTML/CSS/JavaScript, for example in a regular div without using contenteditable=true? Imagine having the following: <div>Hello world</div> If I were to click between the "w" a ...

Utilizing shared functions defined across different controllers

Can I utilize the code within these controllers for other purposes? .controller('GenericController', ['$scope', '$controller', '$rootScope', '$dialogs', '$state', '$http', '$modal& ...

What is the method for determining the number of unique tags on a webpage using JavaScript?

Does anyone have a method for determining the number of unique tags present on a page? For example, counting html, body, div, td as separate tags would result in a total of 4 unique tags. ...

JavaScript code is showing a parsing error

Hey everyone, I'm encountering an error that seems to be caused by the last part of my code. Can someone help me figure out what's wrong? Error Prompt: Parse error: syntax error, unexpected '[', expecting ',' or ';&apos ...

After the AJAX request, $this experienced a loss of focus

I am facing an issue with my CakePHP code snippet below: <tr class="tr_clone"> <td><?php echo $this->Form->input('items][',array('label'=>false,'options'=>$items,'class'=>'it ...

What is the best way to conceal an image tag depending on an ajax response?

What is the correct jQuery statement to replace the "//Needed incantation" comments below so that the image tags are displayed or hidden based on the AJAX responses? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR ...

Having trouble rendering SVG image using ReactJS

Trying my hand at learning React JS through a tutorial, I created a reusable component to display information. However, I encountered an issue where my SVG image is not displaying properly. Take a look: https://i.sstatic.net/dhK4D.png Notice how the imag ...

Can one upload a file through ExtJS 4 without using a form?

Is there a way to upload a file without submitting a form in ExtJS 4? If so, how can this be achieved? Thank you. ...

Path taken to reach the view requested by Node.js server

Snippet of Controller Code: bina: function(req, res) { var request = require('request'); request({ url: 'http://localhost:3000/bina/', method: 'GET', }, function(err, res, body) { ...