0

I have a controller I am calling an API on MVC. This API returns me back a partial view, This partial view is associated with my controller from which I am calling the API .

Now as soon as I getting the partial view back, I am vanishing the html of the view and then re-rendering the view.

but my controller method never get initated, I guess because the controller is already initiated.

Question is can I call method of controller when it loads back.

html :

<div id="pageholder">
            <-- here is my view , which I am changing thru API , and I want to re render it, and also want to perform certain controller methods -->
            </div>

ANGULAR :

$http({
    method: 'POST',
    url: url,
    data: {
        config: item,
        parameter: itemParametrs
    }

}).success(function(data, status) {
    $('#pageholder').empty();
    $scope.username="username";
    $('#pageholder').html(data);
});

PLEASE HELP!

1
  • to render the html you can call $apply since you're not using angular directives to manipulate the DOM it does not get called.. to rerender the controller you can either have a function that calls some init function meaning after success just call your init function... or I guess you could refresh the page. Commented Nov 25, 2015 at 22:06

1 Answer 1

1

You need to compile that new HTML you get. No directive or controller will be watched by Angular if you dynamically write HTML:

.success(function(data, status) {
  $scope.username="username";

  var $pholder = $('#pageholder');
  $pholder.empty();
  $pholder.html(data);

  // Recompile the HTML so angular can process it
  $compile($pholder)($scope);
});

PS: you will need to get the $compile service in your directive/controller (the same way you get $http)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.