0

I have following controller which works just fine for dynamic compilations of new DOM elements after some ajax actions:

angular.module('cms').controller('CompileHtmlCtrl', [
  '$scope', '$compile',
  function ($scope, $compile) {
    $scope.compileHtml = function (id) {
      $compile("#"+id)($scope);
    };
  }
]);

Problem comes when I was trying to change URL in reaction on ajax action because if I call pushState anywhere (after or before compilation), angular will allways change the URL back.

window.history.pushState({}, '', url);

Is possible to prevent angular doing that?

Resolved using $digest.

$compile("#"+id)($scope);
$scope.$digest();

Then I have found mayby better solution turning off angular URL manipulation Turn off URL manipulation in AngularJS.

Community
  • 1
  • 1
Petr Přikryl
  • 1,641
  • 4
  • 22
  • 34

1 Answers1

0

You should be using a directive in your view instead of a controller, that way you can change the ajax data in the view which is more the Angular way of doing this. In order to solve your problem we need to know what Angular router you are using.

enf0rcer
  • 545
  • 2
  • 11