Answer the question
In order to leave comments, you need to log in
How to initialize controller in angularjs after Ajax?
I have a question about angularJs.
I have one controller which is responsible for loading templates. The essence of this controller is to call a function when the url (history api) changes, the function itself makes an Ajax request to the server and returns the HTML code of the page in which its controller is connected to process the document, something like this
$http.post($location.url(), xx).then(function( result ) {
$scope.myTemplate = $sce.trustAsHtml( result.data );
}, function( result ) {
console.log( result );
})
$scope.myTemplate
and displayed it on the page
Everything is great! But how can I now initialize the controller that belongs to this template in this template (myTemplate)?
In this piece, I connected the controller to the very bottom, registered it in ng-controller and nothing happened.
Help me to understand. <div ng-bind-html="myTemplate"></div>
Answer the question
In order to leave comments, you need to log in
$scope.templateUrl = $location.url();
ng-bind-html is not designed to compile and bind a template (if you know what I mean)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question