简体   繁体   English

使用AngularJS调用jQuery插件函数

[英]call jQuery plugin function using AngularJS

i spent a lot of time trying to call jQuery plugin function using angular. 我花了很多时间试图使用angular来调用jQuery插件函数。 So far no success. 到目前为止没有成功。 I want to use fancybox(jQuery) plugin using angularJS. 我想使用angularJS使用fancybox(jQuery)插件。

My fiddle: http://jsfiddle.net/lukiux666/LyaespL1/ fiddle is set to jQuery 2.2.1 so you can see how it has to look, but i need the same using only angular. 我的小提琴: http : //jsfiddle.net/lukiux666/LyaespL1/小提琴设置为jQuery 2.2.1,因此您可以看到它的外观,但是我只需要使用角度就可以了。

I need to call this function jquery in angularjs: 我需要在angularjs中将此函数称为jquery:

$(document).ready(function() {
$(".fancybox").fancybox(); 
 });

my last attempt was 我最后的尝试是

angular.module('MyApp', [])
.controller('MyCtrl', [function() {

angular.element(document).ready(function () {
    angualr.element(".fancybox").fancybox();
});
}]);

I really need this to work, thank you so much in advance. 我真的需要这项工作,非常感谢。

Use angular directives, I change your fiddle and implement with directives, 使用角度指令,我改变了你的提琴,并用指令实现,

angular.module('MyApp', [])

.directive('fancybox', [function() {
    function link($scope, $element){
        $element.fancybox();
    }
    return {
       restrict: 'AE',
       link: link
    }
}]);

look this fiddle 看这个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM