Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS Fancybox Popup

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 attempting to open the template in the code shown below in a fancybox window.

View

<a href="" ng-click="openPage('popups/add.html')">ADD</a>

Controller

app.controller('MainController',
    function MainController($scope) {
        $scope.user = "Hey Welcome";

        $scope.open = function(template_path){
            $.fancybox({"href":template_path})
        }
    }
)

And popup/add.html

<div class="pop-contnr">
    <h2>ADD</h2>
    <table>
        <thead>
            <tr>
                <th align=center>{{user}}</th>
            </tr>
        </thead>
    </table>
</div>

Fancybox successfully opens a window containing the template, but the {{user}} expression has not been evaluated. Can anyone please help?

like image 921
Miqdad Ali Avatar asked Apr 14 '14 09:04

Miqdad Ali


1 Answers

I have created a directive for fancybox

app.directive('fancybox',function($compile, $timeout){
    return {
        link: function($scope, element, attrs) {
            element.fancybox({
                hideOnOverlayClick:false,
                hideOnContentClick:false,
                enableEscapeButton:false,
                showNavArrows:false,
                onComplete: function(){
                    $timeout(function(){
                        $compile($("#fancybox-content"))($scope);
                        $scope.$apply();
                        $.fancybox.resize();
                    })
                }
            });
        }
    }
});
like image 85
Miqdad Ali Avatar answered Nov 12 '22 06:11

Miqdad Ali