Template always compiles with old scope value in directive
问题 I've got a directive that's working like this: http://jsfiddle.net/smithkl42/cwrgLd0L/23/ App.directive('prettify', ['$compile', function ($compile) { var templateFn; return { restrict: 'E', scope: { target: '=' }, link: function (scope, element, attrs) { if (!templateFn) { var template = element.html(); templateFn = $compile(template); } scope.$watch('target', function (newVal, oldVal) { var compiled = templateFn(scope); element.html(''); element.append(compiled); var html = element.html();