Skip to content

Instantly share code, notes, and snippets.

@andreareginato
Created October 26, 2013 16:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andreareginato/7171134 to your computer and use it in GitHub Desktop.
Save andreareginato/7171134 to your computer and use it in GitHub Desktop.
'use strict';
var directives = angular.module('login.directive', []);
directives.directive('login', ['$rootScope', '$compile', '$http', '$templateCache',
function($location, $rootScope, $compile, $http, $templateCache) {
...
definition.link = function postLink(scope, element, attrs) {
scope.$watch('client', function(value) {
init();
compile();
});
var init = function() {
scope.template = scope.template || 'views/templates/default.html';
}
var compile = function() {
var loader = $http.get(scope.template, {cache: $templateCache});
var promise = loader.success(function(html) {
element.html(html);
}).then(function (response) {
element.replaceWith($compile(element.html())(scope));
console.log(element.html());
});
};
scope.$on('login:template', function(event, template) {
scope.template = template;
compile(scope);
});
};
return definition
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment