Domanda

I have a app with code i want to prettify with prettify.js, but i cant get the apply method to work with angular 1.2. However it works with 1.1.

Because i cannot load the prettify lib on the body load because of angular, i have tried creating a filter like this

App.controller('myCtrl', function($scope) {
    setTimeout(function() {
        $scope.text = "function apply() { return 'not working..'; }";
        $scope.$apply();
    }, 0);
});

App.filter('pretty', function(){
    return function(text) {
        return prettyPrintOne(text);
    }
})

And the HTML

<div ng-app="Knob" ng-controller="myCtrl">
    <pre ng-bind-html-unsafe="text|pretty"></pre>
</div>

Here the working fiddle: working fiddle.

When angular is changed to 1.2 apply breaks (or maybe something else?)

Failing fiddle (same code, updated angularjs ) broken fiddle

È stato utile?

Soluzione

The problem isn't that $apply isn't working, it's that ng-bind-html-unsafe was removed. Check out this answer for more info.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top