AngularJS Fancybox Popup

前端 未结 3 620
挽巷
挽巷 2020-12-15 13:12

I have started an angularjs project and I would like to implement fancybox.

For this, I have included the jQuery and fancybox plugins to the solution. I am attemptin

3条回答
  •  萌比男神i
    2020-12-15 13:59

    I extended the answer above to use Angular's template cache.

    It is invoked in the markup like this:

    Open Fancybox

    The code for the directive is:

    app.directive('fancybox', function ($templateRequest, $compile) {
        return {
            scope: true,
            restrict: 'A',
            controller: function($scope) {
                $scope.openFancybox = function (url) {
                    $templateRequest(url).then(function(html){
                        var template = $compile(html)($scope);
                        $.fancybox.open({ content: template, type: 'html' }); 
                    });
                };
            },
            link: function link(scope, elem, attrs) {
                elem.bind('click', function() {
                    var url = attrs.fancyboxTemplate;
                    scope.openFancybox(url);
                });
            },
        }
    });
    

    Here's the plunker.

提交回复
热议问题