调用 $(document).foundation();基金会多次

Calling $(document).foundation(); multiple times in Foundation

我是第一次使用 Foundation 并在现有的 Angular Dart 应用程序中使用它。

可以多次调用$(document).foundation();吗?

在我的 JS 中,我有以下内容:

document.addEventListener("onFoundationify", function(event){
    $(document).foundation();
});

然后在我的 Angular 组件的 Dart 代码中调用

@override
ngAfterContentInit() {
    document.dispatchEvent(new CustomEvent("onFoundationify"));
}

所以每个 Dart 组件都会在 ngAfterContentInit 上触发此事件,然后调用 $(document).foundation();

是否有更好的方法来建立刚刚出现在 DOM 中的 Angular Dart 组件,或者我正在做的事情是否安全?

这似乎是一种更简洁的方法:

Angular飞镖:

@override
ngAfterContentInit() {
    new Future.delayed(Duration.ZERO, (){
        document.dispatchEvent(new CustomEvent("onSetupAccordian"));
    });
}

JavaScript:

<script type="text/javascript">
    document.addEventListener("onSetupAccordian", function (event) {
        new Foundation.Accordion($("element-id-from-event"), {});
    });
</script>

这明确地设置了特定的手风琴,而不是重新连接所有东西。