I am working on a news feed page with angular.js and jquery.
I am using a directive to detect the last feed to show. when it return scope.$last ==true
, I call a function to do some Jquery animation.
Then, I added a ng-model showYear
to filer elements by date, and added ng-if
to filter elements.
My problem is, when the last element is filtered by ng-if
and not rendered,
the directive can not detect scope.$last
and run feedPosition()
.
I've tried to do it like the url below but it face the same problem: here.
Kindly please Help.
here's my code:
HTML:
<div id="feedList">
<div ng-repeat="feed in feeds | orderBy: '-date'" ng-if="show(feed.date)" feed-list-repeat-directive>
//some content here
</div>
</div>
Javascript:
<script>
var feeds = [{
"type" : "publications",
"source" :"AAA",
"date" : new Date(2014, 4, 10),
"title" : "title 2014",
"thrumb" : "thrumb1.jpg"
},{
"type" : "tvc",
"source" : "BBB",
"date" : new Date(2015, 4, 10),
"title" : "title 2015",
"thrumb" : "thrumb2.jpg"
}];
var app = angular.module('anApp', []);
app.controller('anCtrl', function($scope) {
$scope.showYear = 2015;
$scope.feeds = feeds;
$scope.show = function(yr){
return Number(yr.getFullYear())==$scope.showYear;
};
})
.directive('feedListRepeatDirective', function() {
return function(scope, element, attrs) {
if (scope.$last){
feedPosition(true);
};
};
});
function feedPosition(){
for(a=0; a<$('#feedList > div').length; a++){
// do something to animate elements position
};
};
</script>