将jquery ui组件封装为angularjs指令

时间:2013-08-02 17:07:06

标签: jquery angularjs

是否有可用的库基本上可以使用任何jquery ui组件并将其转换为angularjs指令,我需要零配置?

换句话说,我正在寻找一种方法来“免费”获得大量纯粹的angularjs ui指令。

2 个答案:

答案 0 :(得分:3)

为什么不将它们用作Angular服务?

我需要在Angular Controller中使用jQuery Carousel。所以我创建了一个名为Animation的应用来托管我的AnimationService,就像这样

app.js:

'use strict';

var animation = angular.module('animation', []);

service.js:

animation.service('AnimationService', function($timeout) {

    this.carousel = function(element, options) {
        $(element).tinycarousel(options);
    };

});

之后我只需要注入我的角度应用程序:

app.js:

var myApp = angular.module('myApp', ['animation']);

在我的角度控制器上注入:

myApp.controller('MyCtrl', function ($scope, $http, AnimationService) {

});

最后我像这样调用旋转木马(在我的控制器内):

AnimationService.carousel('.slider', { pager: true });

第一个参数是元素,第二个参数是jquery.carousel选项。

希望这可以提供帮助。如果您需要任何进一步的解释或示例,请与我们联系

答案 1 :(得分:0)

这里的答案很晚,但angular-ui project has a directive称为“jQuery Passthrough”,它允许您从Angular中轻松调用jquery函数。我已经使用了几次,对我来说它运作得很好。

我不认为这不是你要求的具体内容,但是如果目标是从Angular轻松地挂钩一些jQuery代码而不必编写自己的指令那么这很有效。祝你好运。

相关问题