gpt4 book ai didi

javascript - Angular 和 Masonry 协同工作

转载 作者:行者123 更新时间:2023-12-03 07:05:36 24 4
gpt4 key购买 nike

我没有让 masonry 在 ng-repeat 中工作。

我尝试添加一个类 masonry-container,并在我的 ng-repeat 中使用类 masonry-item。

在我的 js 中,我使用这两个类,我的 js 文件加载如下:-jquery-石工-我的文件

  1. HTML)

<div class="masonry-container" >
<div ng-repeat="link in links">
<div class="masonry-item col-sm-4">
<div class="jumbotron">
<div>
{{link.title}}
</div>
<div>
{{link.url}}
</div>
</div>
</div>
</div>
</div>

1.1JS)

$(document).ready(function(){

$('.masonry-container').masonry({
// options
itemSelector: '.masonry-item',
columnWidth: '.masonry-item'
});
});

最佳答案

我不知道 masonry ,但是当你的 JS 执行时,Angular 还没有渲染模板。

要执行您想做的操作,您应该使用指令并将代码放入link函数中。

angular.module('Example', [])
.directive('masonry-container', [function () {
return {
link: function ($scope, element, attributs, controllers) {
element.masonry({
// ...
});
// ...
}
};
}])

Directives that want to modify the DOM typically use the link option to register DOM listeners as well as update the DOM. It is executed after the template has been cloned and is where directive logic will be put.

https://docs.angularjs.org/guide/directive

关于javascript - Angular 和 Masonry 协同工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36838854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com