SO - Select OrderByIssue

http://stackoverflow.com/questions/22938958/does-orderby-only-work-the-first-time-with-ng-options

by ncapito

HTML

<div ng-controller="StoriesController">
    <li ng-click="storyConfig.filter='all'">
        <div>All</div>
    </li>
    <li ng-click="storyConfig.filter='watch'">
        <div>Watch</div>
    </li>
    <li ng-click="storyConfig.filter='movement'">
        <div>Move</div>
    </li>
    </ul>
    <li ng-repeat="story in filteredStories = (allStories | stories:storyConfig.filter | orderBy:'datePosted':true)" ng-click="storyConfig.activeStoryId=story._id;">
        <div>
            <div class="center">
                 <h3>{{story.datePosted}}</h3>

            </div>
            <div>
                 <h4>{{story.headline}}</h4>

            </div>
        </div>
    </li>
    <li ng-if="filteredStories.length === 0 && storyConfig.filter === 'watch'">
        <div>
            <div class="center">
                 <h6>You are not watching any stories</h6>

            </div>
        </div>
    </li>
</div>

CSS

select {
    height: 150px;
    margin-bottom: 10px;
}

JavaScript

var app = angular.module('myApp', []);
app.filter('stories', [function () {
    return function (stories, filter) {

        return stories.filter(function (story) {
            var add = false;
            if (filter === 'all' || (filter === 'movement' && story.movement === true)) {
                add = true;
            } else if (filter === 'watch') {
                angular.forEach(story.tags, function (tagId) {
                    var tag;// = StoryService.getTag(tagId);
                    if (tag !== undefined && tag.watch) {
                        add = true;
                    }
                });
            }

            return add;
        });
    };
}]);

app.controller('StoriesController', ['$scope', '$rootScope',

function ($scope, $rootScope) {

    $scope.storyConfig = {};
    $scope.allStories = StoryService = [
        {datePosted: new Date(),_id:  1,headline:'test'},
            {datePosted: new Date(),_id:  2,headline:'test2'},
    
        {datePosted: new Date(),_id:  3,headline:'test3'}
    
    ]//;.getAll();
    $scope.storyConfig.filter = 'all';


    if ($scope.storyConfig.activeStoryId === undefined) {
        $scope.storyConfig.activeStoryId = $scope.allStories[0]._id;
    }
   
}]);