var angular = require('angular');
require('jsUtil');
require('../modules');

var module = angular.module('commons.directives.compile');

module.directive('compile', function($compile) {
  return function(scope, element, attrs) {
    scope.$watch(
      function(scope) {
        return scope.$eval(attrs.compile);
      },
      function(value) {
        if(jsUtil.isEmpty(value)) {
          value = '';
        }
        element.html(value);
        $compile(element.contents())(scope);
      }
    );
  };
});
