【发布时间】:2017-11-11 19:23:52
【问题描述】:
我需要在指令中执行一些 jquery,我是 Angular 的新手,我不知道该怎么做。
var temp = "<div class='cell' style='width:{width}px; height: {height}px; background-image: url(i/photo/{index}.jpg)'></div>";
var w = 1, html = '', limitItem = 49;
for (var i = 0; i < limitItem; ++i) {
w = 200 + 200 * Math.random() << 0;
html += temp.replace(/\{height\}/g, 200).replace(/\{width\}/g, w).replace("{index}", i + 1);
}
$("#freewall").html(html);
var wall = new Freewall("#freewall");
wall.reset({
selector: '.cell',
animate: true,
cellW: 20,
cellH: 200,
onResize: function() {
wall.fitWidth();
}
});
wall.fitWidth();
// for scroll bar appear;
$(window).trigger("resize");
}
这是您可以在https://github.com/kombai/freewall 中检查的查询,我需要在角度指令中执行它,或者如果您知道更高效的方式,您可以在这里分享
【问题讨论】:
-
永远不要使用带角度的 Jquery。强烈推荐。
-
Angular Material 在不依赖 JQuery 的情况下提供此功能,正如 @Mr_Perfect 所说,这在 Angular 中是不好的做法。 material.angularjs.org/latest/demo/gridList
-
是的,不要这样做。您的下一个问题将是“为什么我的任何 Angular 绑定都不再工作了?”这将是因为您通过使用
$(...).html()覆盖而破坏了它们。
标签: jquery angularjs angularjs-directive freewalljs