Issue with Angular's date filter when used in combination with ng-repeat

JavaScript Controller

app.controller("MarketController", function ($scope) {
    $scope.dates = [
        { date: Date.parse("01/01/1999"), value: 123.456 },
        { date: Date.parse("02/05/2004"), value: 789.123 }
    ];
});

HTML Template

<li ng-repeat="item in dates">
    <span>{{item.date | date: 'EEE'}}</span>
</li>

I am having trouble getting the correct date output using the filter, any suggestions on how to fix it?

Answer №1

Solution Confirmed:

var application = angular.module('testing', []);
application.controller("MarketController", function($scope) {
  $scope.dates = [{
    date: Date.parse("01/01/1999"),
    value: 123.456
  }, {
    date: Date.parse("02/05/2004"),
    value: 789.123
  }];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script>

<div ng-app='testing' ng-controller='MarketController'>
  <li ng-repeat="item in dates">
    <span>{{item.date | date: 'EEE'}} - {{ item.value }}</span>
  </li>
</div>

It's possible that you made an error with ng-repeat.

Answer №2

Here's a tip for filtering dates:

$filter('date')(date, 'yyyy.dd.MM');

Remember to include the $filter in the following line:

..['$scope', '$filter', function($scope, $filter){...}

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

Beautiful prompt interface for HTML

I'm attempting to create a sweet alert using the HTML option: swal({ title: "HTML <small>Title</small>!", text: "A custom <span style="color:#F8BB86">html<span> message.", html: true }); Instead of just text, ...

Utilize the directive method within the transcluded content by making a call

Trying to call a method within a directive from transcluded content. The structure of my HTML is: <typeahead class="typeahead" model="customers" filtered-model="customersfiltered" ng-model="selectedcustomer"> <ul> <li ng-click="select ...

Error encountered while integrating sweetalert into Vue.js framework

Can anyone help me with importing sweetalert2 correctly to use Swal in this file only? I tried using <script src = "https://cdn.jsdelivr.net/npm/sweetalert2@9"> but it's not working as expected. What could be the issue? <script ...

What is preventing my Three.js object from responding to my commands to move?

I'm currently working on a three.js project where I want to create a block that moves when different keys are pressed. I've managed to set up a functional event listener, used console.log() for checking purposes, and successfully moved the block ...

What is the best way to stop a vimeo video within a dynamic iframe?

I have a collection of items that trigger the loading of an iframe when clicked. I want to ensure that only one iframe is open at a time, and when a new one is opened, the previous one should pause if it is playing. Although I have attempted to implement ...

Troubleshooting a ForwardRef issue in a TypeScript and React Native project

Encountering a ts error while using forwardRef. // [ts] Property 'forwardRef' does not exist on type 'typeof React'. const MyComponent = React.forwardRef((props: Props, ref: any) => ... An issue arises in React Native when the pare ...

How can I use JavaScript and HTML to print a canvas that is not within the print boundaries?

As someone who is new to javascript, I recently created a canvas function that allows me to successfully print. However, I am encountering an issue with printing large canvas areas. When I navigate to the further regions of the canvas and try to print, i ...

What is the reason for the hotel's Object _id not being saved in MongoDB?

Can you assist with troubleshooting this issue? This is the HotelRoom Module: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const HotelRoomSchema = new Schema({ name : { type : String, require : true ...

Guidance on calling a JavaScript function from a dynamically added control

The Master page includes a ScriptManager. Next, I have a Control with a ScriptManagerProxy and an UpdatePanel. Within the UpdatePanel, I dynamically insert another Control (which also has a ScriptManagerProxy) that needs to run some JavaScript code. In ...

"Exploring the role property of the userdata in a mock JSON server: a step-by-step guide

This is a sample Json object { "UserData": [ { "name": "Alice", "password": "abc123", "role": "user" }, { "name": "Bob", & ...

Clicking on another function - JavaScript

I'm looking for a way to capture the onclick function of a div and trigger it when the backKey is pressed. Any help would be greatly appreciated! document.addEventListener("keydown", keyDownTextField, false); function keyDownTextField(e) { var k ...

Tips on triggering a function defined within an AngularJS scope using an event handler

I am in the process of creating a custom directive that generates a menu by processing an array of menu entries defined as objects. The menu works perfectly fine and appears as a pop-over above the page content. Everything seems to be in order so far. Ho ...

The AngularJS Popover and its Template Fail to Display

I have successfully created a UI Bootstrap popover in AngularJS on my CodePen, but when I try to implement it at work, it doesn't appear at all. Interestingly, the Dynamic Popover from the UI Bootstrap Demos works perfectly fine. The only problem seem ...

Generating examples of two models that are interdependent

In my Javascript form, I have implemented an AJAX POST request that successfully creates a new instance of a model called Component. Now, my goal is to allow users to input keywords for the Component model through the same form. To achieve this, I have al ...

Deleting an object with javascript in django: A step-by-step guide

Is there a way to use JavaScript to create a confirmation window before deleting an item? <div class="card-footer"> <a href="{% url 'course_delete' student.slug %}"><button>Delete</button>&l ...

The attempt to access https://registry.npmjs.org/yargs was unsuccessful

I am experiencing difficulties in downloading packages from npm. When attempting to download from https://registry.npmjs.org/yargs, I am receiving an error message that states: write EPROTO 101057795:error:14077419:SSL routines:SSL23_GET_SERVER_HELLO:tls ...

Incorporating a weather widget into the information window of a Google map

I am having some trouble trying to integrate a weather widget from into an Info Window on a Google map. The goal is to have the weather widget open in the Info Window when a marker on the map is clicked. The code snippet for embedding the weather widget ...

PostBackUrl="javascript:void(0);" prevent postback from occurring for all controls within the webpage

Is there a way to prevent postback for a specific control on the page? I've managed to achieve this successfully. However, after clicking on that control, all other controls on the page do not trigger any postbacks. Everything was working fine until I ...

Transform js into a more dynamic format to avoid redundancy when displaying items upon click

I came across a simple lightbox code snippet, but it's based on IDs and I plan to use it for more than 20 items. I don't want to manually write out 20 JavaScript lines when there could be a more efficient way to handle it dynamically. My JS skill ...

JavaScript Alternatives for jQuery Functions

Currently in the process of eliminating the jQuery dependency from my AngularJS project, I encountered the following code as part of a spec within my codebase: beforeEach(inject(function($rootScope, _$compile_) { scope = $rootScope; $compile = _$c ...