Tags » Ken Smith

Template always compiles with old scope value in directive

I’ve got a directive that’s working like this:

http://ift.tt/1AipN7d

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();
                var prettified = prettyPrintOne(html);
                element.html(prettified);
            }, true);
        }
    };
}]);
… 86 more words
Recent Questions - Stack Overflow

Using $compile in a directive triggers AngularJS infinite digest error

Any thoughts on why this directive is triggering an infinite digest error?

http://ift.tt/1uOtfBL

var App = angular.module('prettifyTest', []);
App.controller('myCtrl', function ($scope) {
    $scope.message = 'Hello, world!';
})

App.directive('prettify', ['$compile', function ($compile) {
    var template;
    return {
        restrict: 'E',
        link: function (scope, element, attrs) {
            if (!template) {
                template = element.html();
            }
            scope.$watch(function () {
                var compiled = $compile(template)(scope);
                element.html('');
                element.append(compiled);
                var html = element.html();
                var prettified = prettyPrintOne(html);
                element.html(prettified);
            });
        }
    };
}]);
… 122 more words
Recent Questions - Stack Overflow

Colorado Cancer Patient Raising Funds This 'Movember' By Growing Mustache

FORT COLLINS, Colo. (CBS4) – “Without a doubt Sam Elliot has the greatest mustache,” said Ken Smith of Fort Collins.

Smith is growing a mustache for Movember. 239 more words

News

Book Review: Riding the Big One

Riding the Big One

Ken Smith

It’s all hands on ‘dick’ for 18 year old Sandy in this naughty, nautical novel.  School’s over for our young hero and a new life in the Navy introduces this horny virgin to outrageous night-time adventures and man-on-man fun.

209 more words
Reading

Brandmeier Rewind- Thursday 10.23.14

Neil Diamond explains Sweet Caroline; Barry Manilow sings with dead people; Chicago’s top-selling restaurants; sports reporter Ken Smith talks Cubs, Foo Fighters, and ah cha cha cha… 10 more words

Jonathon Brandmeier

Brandmeier Rewind- Thursday 10.23.14

Neil Diamond explains Sweet Caroline; Barry Manilow sings with dead people; Chicago’s top-selling restaurants; sports reporter Ken Smith talks Cubs, Foo Fighters, and ah cha cha cha… 10 more words

WGN FM