I am currently attempting to integrate the angular-masonry plugin by passy with an infinite scroll directive, but I'm encountering some issues. I have set up a plunk for this here. The console is displaying an error message that reads "TypeError: Object [object Object] has no method 'imagesLoaded'."
Below is my HTML code:
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.2.13" src="http://code.angularjs.org/1.2.13/angular.js"></script>
<script data-require="jquery@*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script data-require="masonry@*" data-semver="2.1.0-7" src="//cdnjs.cloudflare.com/ajax/libs/masonry/2.1.07/jquery.masonry.min.js"></script>
<script data-require="imagesloaded@*" data-semver="v3.0.2" src="http://desandro.github.io/imagesloaded/imagesloaded.pkgd.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="angular-masonry.js"></script>
<script src="myApp.js"></script>
</head>
<body ng-app="myApp" ng-controller="DemoController">
<div masonry="">
<img class="repeated-img masonry-brick" ng-repeat="image in images" ng-src="http://placehold.it/225x{{image.height}}/{{image.color.bg}}/{{image.color.text}}&text={{image.num}}" />
</div>
<div scroll-trigger="loadMore()" threshold="100">Trigger element</div>
</body>
</html>
Here are my infinite scroll directive and app module:
var myApp = angular.module('myApp', ['wu.masonry']);
myApp.controller('DemoController', function($scope) {
$scope.images = [
{num: 1, height:400}, {num: 2, height:250},
{num: 3, height:225}, {num: 4, height:200},
{num: 5, height:200}, {num: 6, height:225},
{num: 7, height:300}, {num: 8, height:250},
{num: 9, height:275}, {num: 10, height:350},
{num: 11, height:450}, {num: 12, height:275},
{num: 13, height:225}, {num: 14, height:250},
{num: 15, height:250}, {num: 16, height:225}]
$scope.loadMore = function() {
var last = $scope.images[$scope.images.length - 1].num;
var heights = [200, 225, 250, 275, 300, 350, 400, 450]
var colors = ["859994", "51C0C4", "C3D9C6", "EBE2C7", "F5E6D3"]
var textColor = "ffffff";
for(var i = 1; i <= 8; i++) {
var randColor = colors[Math.floor(Math.random()*colors.length)];
$scope.images.push({num: last + i, height: (heights[Math.floor(Math.random()*heights.length)]), color: {bg: randColor, text: textColor}});
}
};
});
myApp.directive('scrollTrigger', function($window) {
return {
link : function(scope, element, attrs) {
var offset = parseInt(attrs.threshold) || 0;
var e = jQuery(element[0]);
var doc = jQuery(document);
angular.element(document).bind('scroll', function() {
if (doc.scrollTop() + $window.innerHeight + offset > e.offset().top) {
scope.$apply(attrs.scrollTrigger);
}
});
}
};
});
Thank you for your help, I am new to angular so any assistance is appreciated.