My scenario involves hitting a specific route (#/abc
) and then making a POST request to the server to render the HTML received as a response. Instead of embedding this logic directly into $routeProvider.when
, I came up with my own solution.
This is how I tackled it:
- Navigate to the designated route
- Load an empty view in the ng-view (utilized elsewhere in the app)
- The empty view contains a div with
<div ng-bind-html=responseHtml></div>
- In the controller, execute a
$http.post
and assign the returned data to$scope.responseHtml = $sce.trustAsHtml(data);
While this method works well, I have encountered difficulties setting any bindings within the responseHtml.
You can access the corresponding JSFiddle here: http://jsfiddle.net/prakhar1989/LX26M/2/
Being new to AngularJS development, I am uncertain if my approach is optimal. Any advice or pointers would be greatly appreciated!
Thank you!