AngularJS:初始化 ZURB Foundation JS [英] AngularJS: initialize ZURB Foundation JS
问题描述
我同时使用 AngularJS 和 Foundation.
I am using both AngularJS and Foundation.
要初始化 Foundation JS,您必须进行以下调用:
To initialize Foundation JS, you have to make the following call:
$(document).foundation();
在 AngularJS 应用程序中进行此调用的最佳方法是什么?代码示例将不胜感激.
What would be the best way to make this call in an AngularJS application? Code examples would be appreciated.
此外,如果我要围绕 Foundation JS 组件编写指令,我如何确保 Foundation 已初始化?
Also, if I were to write a directive around a Foundation JS component, how could I ensure that Foundation is initialized?
推荐答案
您可以$apply
将代码引入 Angular 框架.这是一个使用 $rootScope
和 run
的例子,这也可以在控制器/指令中使用任何 $scope
来完成:
You could $apply
the code in order to bring it into the Angular framework. Here is an example using $rootScope
with run
and this could also be done inside a controller/directive with any $scope
:
app.run(function($rootScope){
$rootScope.$apply($(document).foundation());
});
另一种选择::
$compile($(document).foundation())($scope);
请务必在您的控制器/指令中包含 $compile
服务,以便以这种方式使用它.例如:
Be sure to include the $compile
service in your controller/directive to use it this way. E.g.:
app.directive('mydirective', function($compile) {
return {
link: function(scope, element, attrs) {
$compile($(document).foundation())(scope);
}
}
});
这篇关于AngularJS:初始化 ZURB Foundation JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!