Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:11:45+00:00 2026-06-15T15:11:45+00:00

I am new to angularjs world and am trying to do something that I

  • 0

I am new to angularjs world and am trying to do something that I think should be achievable with a directive.

I have a template which has a list of articles listed using ng-repeat. These articles have a date on them. I want to group the articles by date in the template. So I am thinking of creating a directive that would append a new div before each group of articles in that day. The data in the model is already sorted by date desc.

Should I be using the compile function in the directive to do this ? Any code examples would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:11:46+00:00Added an answer on June 15, 2026 at 3:11 pm

    If I understand you correctly you want the output to be something like:

    <ul>
        <li>
             Show 3 articles for date 2012-12-07
        </li>
        <li>
             Show 1 articles for date 2012-12-06
        </li>
        <li>
             Show 2 articles for date 2012-12-05
        </li>
    </ul>
    

    In that case, I would do the grouping before it renders:

    function ArticlesController ($scope) {
        var groupArticles = function (articles) {
            var i,
                art = {};
    
            for (i = 0; i < articles.length; i += 1) {
                if (!art.hasOwnProperty(articles[i].date)) {
                    art[articles[i].date] = [];
                }
    
                art[articles[i].date].push(articles[i]);
            }
    
            return art;
        };
        $scope.articles = [{ date: '2012-12-07', title: 'Marcus' },
                           { date: '2012-12-07', title: 'Zero' },
                           { date: '2012-12-06', title: 'Moxxi' },
                           { date: '2012-12-05', title: 'Dr Zed' }];
    
        $scope.groupedArticles = groupArticles($scope.articles);
    }
    

    And you view:

    <ul data-ng-controller="ArticlesController">
        <li data-ng-repeat="articles in groupedArticles">
            <div data-ng-repeat="article in articles">
                {{ articles.title }}
            </div>
        </li>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to angularjs and python and I have this problem. I've been trying
I am fairly new to using AngularJS, and what I am trying to do
Im very new to AngularJS (4 hours new) and I'm trying to get an
I am new to AngularJS and trying to learn the ropes. I'm using the
I'm new to AngularJS and i'm trying to imagine myself, how to do this
I'm using AngularJS 1.0.2 with jQuery 1.8.2 and I'm trying to have AngularJS inject
I'm trying to use a jQuery plugin ( Plupload ) with AngularJS. I have
I have created an AngularJS directive to wrap a Geocomplete plugin for Google Maps
New to PHP and MySQL, have heard amazing things about this website from Leo
new to c#. I'm trying to make a simple system where I can search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.