AngularJS:初始化ZURB基金会JS [英] AngularJS: initialize ZURB Foundation JS
问题描述
我同时使用AngularJS和基础。
I am using both AngularJS and Foundation.
要初始化基金会JS,你必须做出以下调用:
To initialize Foundation JS, you have to make the following call:
$(document).foundation();
什么是做在AngularJS应用此调用的最好方法? code例子是AP preciated。
What would be the best way to make this call in an AngularJS application? Code examples would be appreciated.
另外,如果我写周围基金会JS分量的指令,我又怎能保证基金被初始化?
Also, if I were to write a directive around a Foundation JS component, how could I ensure that Foundation is initialized?
推荐答案
您可以 $适用
的code,以使其在角框架。下面是使用 $ rootScope
的例子与运行
键,这也可以控制器/指令内部完成任何 $范围
:
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);
一定要包括在你的控制器/指令中的 $编译
服务,使用这种方式。例如:
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基金会JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!