Angularjs与Packery.js

fla*_*unk 3 javascript twitter-bootstrap angularjs packery

试图让Packery.js使用我正在使用的angularjs应用程序.

出于某种原因,他们似乎并不能很好地在一起.我认为它可能会被isInitLayout错误的设置解决,但仍然没有爱.

这是我的(bootstrap 3)HTML:

<div class="row" class="js-packery" 
     data-packery-options='{ "itemSelector": ".packery-item", 
                             "gutter": 10,  
                             "columnWidth": 60, 
                             "isInitLayout": false }'>
    <artifact class="packery-item" ng-repeat="(index, thing) in data | limitObjectTo:4" thing="thing"></artifact>
</div>
Run Code Online (Sandbox Code Playgroud)

我开始怀疑这是不是因为我使用的神器指令......

poa*_*r2k 7

如前所述,您必须制定一个处理Packery使用的指令.

该指令使得Packery在我正在开发的项目中使用AngularJS.

工作小提琴:http://jsfiddle.net/8P6mf/2/

HTML:

<div class="wrapper">
    <div ng-repeat="item in test" danny-packery>
        {{item.name}}
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

var dannyPackery = app.directive('dannyPackery', ['$rootScope', function($rootScope) {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            console.log('Running dannyPackery linking function!');
            if($rootScope.packery === undefined || $rootScope.packery === null){
                console.log('making packery!');
                $rootScope.packery = new Packery(element[0].parentElement, {columnWidth: '.item'});
                $rootScope.packery.bindResize();
                $rootScope.packery.appended(element[0]);
                $rootScope.packery.items.splice(1,1); // hack to fix a bug where the first element was added twice in two different positions
            }
            else{
                $rootScope.packery.appended(element[0]);
            }
            $rootScope.packery.layout();
        }
    };
}]);
Run Code Online (Sandbox Code Playgroud)