检测基金会functoin是否已运行

时间:2017-10-03 10:26:32

标签: zurb-foundation

我在Angular4应用程序上使用Zurb Foundation框架。我在几个组件上使用它的不同元素(如下拉菜单,手风琴等),每次运行应用程序时都会收到很多警告,例如:

foundation.min.js:3 Tried to initialize responsive-toggle on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize accordion on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize dropdown-menu on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize responsive-toggle on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize sticky on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize accordion on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize dropdown-menu on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize responsive-toggle on an element that already has a Foundation plugin.
foundation.min.js:3 Tried to initialize sticky on an element that already has a Foundation plugin.

在使用任何需要Javscript的Foundation元素的每个组件上,我运行它:

ngOnInit() {
  // We initalize Foundation framework once the component has loaded
  $(document).foundation();
}

我尝试在主应用程序组件上只运行一次,但一切都停止了。

我想知道是否有办法不显示此警告,或者让基金会检测到它已经加载。

谢谢!

1 个答案:

答案 0 :(得分:0)

我的答案就在眼前:

更改$(document).foundation();

使用新的Foundation控件的每个组件上的$("NEW_FOUNDATION_ELEMENT_SELECTOR").foundation();

因此,例如,在使用基金会手风琴的Angular组件中,ngOnInit中的代码是:

ngOnInit() {
  [...]

  $(".accordion").foundation();
}

对所有组件执行此操作会使警告消失。