How to use Colorbox with Angular JS

kamaci picture kamaci · Feb 1, 2013 · Viewed 7.1k times · Source

How can I use colorbox (fancybox or lightbox is welcome too) with Angular JS, should I write a directive for it is there any other methods for it.

Here is my HTML:

...
<h2 class="box-header">
    <i class="icon-hdd"></i>    
    <div class="btn-group pull-right">      
        <a class="btn btn-mini">
            <i class="icon-zoom-in"></i>
            Expand
        </a>
    </div>
</h2>   
<div id="open-with-colorbox">
...
</div>
...

User will click expand button and div that has open-with-colorbox id will open as colorbox.

PS: I am new to Angular JS that's why I am looking for a solution how to use colorbox, I use twitter bootstrap at my application.

Answer

bmleite picture bmleite · Feb 1, 2013

Write a directive, it's the best option.

Directive example:

app.directive('colorbox', function() {
  return {   
    restrict: 'AC',    
    link: function (scope, element, attrs) {        
      $(element).colorbox(attrs.colorbox);     
    }
  };  
});

HTML:

<a colorbox="{transition:'fade'}" href="...">Image</a>