I have a controller that is working well for dynamically compiling new DOM elements after certain ajax actions:
angular.module('cms').controller('CompileHtmlCtrl', [
'$scope', '$compile',
function ($scope, $compile) {
$scope.compileHtml = function (id) {
$compile("#"+id)($scope);
};
}
]);
The problem arises when I try to change the URL in response to an ajax action because if I use pushState
at any point (before or after compilation), angular always reverts back the URL.
window.history.pushState({}, '', url);
Is there a way to prevent Angular from doing this?
Solution: by using $digest
.
$compile("#" + id)($scope);
$scope.$digest();
I then found a possibly better solution by disabling Angular URL manipulation here: Turn off URL manipulation in AngularJS.